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

dharmendra.sharan@ubs.com dharmendra.sharan at ubs.com
Fri Aug 8 16:01:31 2003


Hi Adrian,

   Thwowable, the parent class of Exception has a method "getMessage()" or "getLocalizedMessage()" [locale specific error message in case you are using internationalization] which allows to get back the message string associated with the exception.

   However if you want to know the call stack trace of where the exception occured, you could ues "printStackTrace()"

   I found this article on google, and seems it will give a nice overview of the exception handling in Java, have a look *and of course there's nothing like the Java tutorial for starters...)
   http://www.developer.com/java/article.php/1455891

   To answer you second question, you need to distinguish between excpetion and error. It is suggested to handle Exception and not the Error, unless there is a solid justification for that. So if you plan to define your own exceptions you would rather use/subclass/inherit from java.lang.Exception than java.lang.Throwable directly.


	Here is part of what Sun has to say about the Throwable class: 
<snip>
"The Throwable class is the superclass of all errors and exceptions in the Java language. Only objects that are instances of this class (or one of its subclasses) are thrown by the Java Virtual Machine or can be thrown by the Java throw statement.  Similarly, only this class or one of its subclasses can be the argument type in a catch clause."
</snip>

	Sun goes on to say: 
<snip>
"Instances of two subclasses, Error and Exception, are conventionally used to indicate that exceptional situations have occurred. Typically, these instances are freshly created in the context of the exceptional situation so as to include relevant information (such as stack trace data)."
</snip>

   Hope this helps,

   Regards,

   Dharmendra

ps: have a nice day!
-----Original Message-----
From: advanced-java-bounces@lists.xcf.berkeley.edu
[mailto:advanced-java-bounces@lists.xcf.berkeley.edu]On Behalf Of Adrian
Soetanto
Sent: Friday, August 08, 2003 5: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

Visit our website at http://www.ubs.com

This message contains confidential information and is intended only 
for the individual named.  If you are not the named addressee you 
should not disseminate, distribute or copy this e-mail.  Please 
notify the sender immediately by e-mail if you have received this 
e-mail by mistake and delete this e-mail from your system.

E-mail transmission cannot be guaranteed to be secure or error-free 
as information could be intercepted, corrupted, lost, destroyed, 
arrive late or incomplete, or contain viruses.  The sender therefore 
does not accept liability for any errors or omissions in the contents 
of this message which arise as a result of e-mail transmission.  If 
verification is required please request a hard-copy version.  This 
message is provided for informational purposes and should not be 
construed as a solicitation or offer to buy or sell any securities or 
related financial instruments.