I\'ve been updating an existing library to throw exceptions to help improve debugging by people using the library.
At first, I thought I\'d define exceptions specific to
I'd use explicitly defined exceptions to give the client code more control. If the client wants to, they can catch IllegalArgumentException
as in your example above. If they need more control, they can catch individual types of exceptions. Consider, for example, a method that could throw two subclasses of IllegalArgumentException. If you don't subclass, you have to do string parsing or some other nonsense to determine the actual cause of the thrown exception. User-defined types solves this issue.