Instead of throwing new Exception("Some message", maybeSomeCause), which means that all callers of my method will need to catch Exception (which can include RuntimeExceptions), I’d like to throw a more specific type of exception when a problem occurs.
I can create my own exception types which extend Exception or another exception type, but I am curious if it is a good idea to re-use some exceptions that come with core Java language, such as:
- IllegalArgumentException
- UnsupportedOperationException
- IOException
- Others?
Are there others that I am missing? I found a basic list of the ‘core’ exceptions here: http://rymden.nu/exceptions.html, with humous explanations.
Thanks!
Edit:
Is there a good list of ‘core’ exceptions?
List so far:
Yes, it’s very good to do that. In fact, it’s even written about in Effective Java, 2nd ed. See item 60 on page 248: “Favor the use of standard exceptions”