This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Sebastian Janisch wrote:Generally, it's always better to work with exceptions that are already contained in the jdk, since this is what other developers are already used to and makes your code easier to handle.
I agree with the "generally" and reject the "always" - since a sentence with "always" is almost always incorrect.
I would say, try to use an exception from the standard Java libraries, if you can find one that's applicable to your situation. Or, try to find an applicable exception from whatever other third-party library or libraries you're using in the same part of the code where you want to throw an exception. But if none of these seems to apply, do go ahead and create a custom exception class, sure. Especially if you're reporting a particular situation that the caller might want to handle differently than they handle a generic "something bad happened" exception.
subject: When we create custom Error and when to create Custom RuntimeException?