tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <>
Subject RE: ServletException not wrapping cause correctly
Date Wed, 13 Oct 2004 14:34:51 GMT

Well, the chances of it being changed on this list are nil ;)  The
chances of it being changed by the JSR154 team are better: contact them
at  If/when the Spec changes,
it will be reflected in our CVS repositories.

Yoav Shapira

>-----Original Message-----
>From: Steve Kirk []
>Sent: Wednesday, October 13, 2004 10:29 AM
>To: 'Tomcat Users List'
>Subject: ServletException not wrapping cause correctly
>The short version is:  ServletException does not appear to wrap causes
>properly - is this a bug, or a case of "works as designed", or am I
>using it wrong?
>Also, what are the chances of it being changed to fall into line with
>other Throwables work?
>More details (from a longer mail that I sent last week):
>> The problem is that when wrapping an Exception with
>> ServletException, it seems to not wrap the underlying cause
>> correctly, in
>> that it cannot be retrieved using Throwable's getCause() method
>> Instead, the cause has to be retrieved using ServletException's own
>> getRootCause() method.  So in the case below, the output is
>> "null" then "java.lang.Exception: My error message":
>> import javax.servlet.ServletException;
>> public class ServletExceptionTest
>> {
>> 	public static void main(String[] args)
>> 	{
>> 		Exception e = new Exception("My error message");
>> 		ServletException se = new ServletException(e);
>> 		System.out.println(se.getCause());
>> 		System.out.println(se.getRootCause());
>> 	}
>> }
>> This means having to write specific code to handle
>> ServletExceptions, rather
>> than being able to treat all Throwables generically.  This seems to
>> against the benefits of inheritance...?  Perhaps
>> ServletException was not
>> retrofitted to the "cause" approach when this was introduced in
>> JDK 1.4?? Or is there something more to it than that, which I'm
>To unsubscribe, e-mail:
>For additional commands, e-mail:

This e-mail, including any attachments, is a confidential business communication, and may
contain information that is confidential, proprietary and/or privileged.  This e-mail is intended
only for the individual(s) to whom it is addressed, and may not be saved, copied, printed,
disclosed or used by anyone else.  If you are not the(an) intended recipient, please immediately
delete this e-mail from your computer system and notify the sender.  Thank you.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message