Throw a long list of exceptions vs throw an Exception vs throw custom exception?

Posted by athena on Stack Overflow See other posts from Stack Overflow or by athena
Published on 2010-12-23T15:51:49Z Indexed on 2010/12/23 15:54 UTC
Read the original article Hit count: 334

Filed under:
|

I have an application which uses two methods of an API. Both these methods throw more than five exceptions each. So, if I just add a throws declaration then it becomes a list of more than ten. (My method cannot handle any of the ten exceptions)

I have read that throwing a long list of exceptions is a bad practice. Also throwing (the umbrella) Exception is a bad practice. So, what should I do?

  1. Add a try catch block, and log and exit in the catch block? (Current approach)
  2. Create a custom exception class, wrap every exception and throw the custom exception?
  3. Add a throws declaration for all exceptions?
  4. Throw Exception?

© Stack Overflow or respective owner

Related posts about java

Related posts about exception-handling