Mask Exceptions Appropriately
Perhaps this should be merged with
and/or other related pages (I did this once, and the original author ignored the merge and restored this page)
You are getting similar exceptions from all over. You don't know what went wrong because all exceptions are simply
or something similar.
where they are thrown or rethrown.
This is similar to
, without hiding where the original exception was thrown. The original exception must be wrapped into the new exception; see
to know how. The idea here is that you should create new exceptions that closely and explicitly indicate what went wrong, as is explained in
. Also avoid
are considered bad style. Whenever a generic exception is thrown, you should mask it into a more meaningful exception.
should be mapped to a meaningful exception like ConnectionException
at the database level or to TransactionException
at the application level.
by doing the following:
at package boundaries so that they make sense.
Now when catching exceptions, try to be as general as possible. Possible in this context means useful and meaningful. Catching
all the time is also bad style. See
of this page (last edited
June 11, 2005
with title or text search