dev@glassfish.java.net

Re: handling unexpected exceptions

From: Tim Quinn <Timothy.Quinn_at_Sun.COM>
Date: Thu, 14 May 2009 16:15:37 -0500

Scott Oaks wrote:
>
> I was just going to bite my tongue, but I will argue that the finally
> clause is far, far better. Exception chaining is a frustrating thing;
> it makes root cause analysis very difficult. I definitely agree that
> in most cases it is a mistake...
What do you mean by "chaining?" By "chaining" I meant throwing a new
exception with the caught one as the cause of the new one. Long chains
of this type make for long stack traces, to be sure, but they also tell
a great deal about the root error and the context in which it occurred.

Now, if by "chaining" you meant catching an exception and then throwing
a new one without bringing the original one along as the cause of the
new one, then that's what I referred to as "masking" which is deadly.
>
> What caused my to put my $.02 after all? I'm just looking right now at
> some appserver code where something threw a NullPointerException,
> which was wrapped in a JDOFatalInternalException, which was wrapped in
> an EJBException, which was wrapped in a
> TransactionRolledBackException, which was wrapped into another
> EJBException. It should be trivial to track down the NPE, but almost
> all information about it is lost (except for the location where it was
> caught, which is something I guess...).
Was the cause of each exception set to the next lower-level one? Or
(shudder) was just the message of each lower-level one captured and set
in each higher-level exception?

Or did I miss your point?

- Tim