[Advanced-java] How To Determine The Appropriate Exception?

James Hicks James.Hicks at effectiveteleservices.com
Fri Aug 8 17:33:28 2003


I tend to create a custom exception hierarchy for my apps.  I start with
ApplicationException extends Exception and SystemException extends
RuntimeException.  I throw these or subclasses of these from the
business layer.  The business layer wraps all non ApplicationException
and SystemException exceptions with one of these or a subclass of these.


In the client code, I catch all throwables and display a nice clean
error to the user.  

If you are using JDK 1.4+ you can use exception chaining.  If you are
using JDK 1.3 or <, you can add exception chaining code to your
ApplicationException and SystemException classes (I believe there is an
article on JavaWorld that shows some examples of this).  Your client
could then call exception.getCause() to get the root exception.  The
exception message is in exception.getMessage().  Likewise, the stack
trace is also availabe along with some other useful information.

James

-----Original Message-----
From: Adrian Soetanto [mailto:adrian@peter.petra.ac.id] 
Sent: Friday, August 08, 2003 4:15 AM
To: advanced-java@lists.xcf.berkeley.edu
Subject: [Advanced-java] How To Determine The Appropriate Exception?


Hi,

Could anyone help me how to determine the appropriate Exception to get
the 
error message thrown by any methods?

Since the Throwable class is the superclass of all errors and exceptions

in the Java language, could we use it in every exception handling?

--
Thank You,
 Adrian

_______________________________________________
Advanced-java mailing list
Advanced-java@lists.xcf.berkeley.edu
http://lists.xcf.berkeley.edu/mailman/listinfo/advanced-java