The Source for Java Technology Collaboration
User: Password:



Start New Message Delete Post a Reply

Article: 
 Exception-Handling Antipatterns
Subject:  Nested exceptions lose vital trace info
Date:  2006-04-20 02:34:55
From:  nbn


I find this article incredibly relevant to many, however, I do have a note to add.

Usually you would wrap exceptions, and catch them as late as possible, but if you happen to troubleshoot from stack traces, you usually see :

xx.xx.Exception: baad user!
trace....
trace...
caused by xx.xx.Exception: baad programmer!
trace..
AND 42 more.... (This is the culprit!!)

The fact that wrapped exceptions traces and especially the root cause exception traces are hidden from the printout is a serious mistake in the implementation.

I know I can read the message, but the call stack is reported top-down, and perhaps not until the bottom of the call stack, which is where the exception occurred.

Before the java.lang.Exception was capable of storing a cause, lots of information was silently lost, but I believe that the way the implementation now handles nested exceptions and their traces is basically a headless implementation.

Now this may be just an opinion, but some programmers actually log the error BECAUSE it may never show otherwise (I've met a few), which make the stack trace even worse because you cannot easily mark the boundaries of the problem.

What do you think?

 Feed java.net RSS Feeds