tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve Kirk" <tomcat-u...@web-startup.co.uk>
Subject ServletException not wrapping cause correctly
Date Wed, 13 Oct 2004 14:29:24 GMT

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 just
using it wrong?

Also, what are the chances of it being changed to fall into line with how
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 later.
> 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 go
> 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 missing?



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message