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: 361
java
|exception-handling
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?
- Add a try catch block, and log and exit in the catch block? (Current approach)
- Create a custom exception class, wrap every exception and throw the custom exception?
- Add a throws declaration for all exceptions?
- Throw Exception?
© Stack Overflow or respective owner