-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Donald,
On 8/28/2011 4:35 PM, Donald Jolley wrote:
>> Exception handling can be configured in WEB-INF/web.xml
>
> This suggestion seems to hold a lot of promise for error handling.
> The only problem is that I have not been able to get it to work. I
> have the following stanza in the web-app container of my web.xml
> file:
>
> <error-page> <exception-type>java.lang.Throwable</exception-type>
> <location>/errors.jsp</location> </error-page>
>
> It is my understanding that the above is a catch-all that will trap
> any error.
Servlets aren't allowed to throw Throwable directly, so that might be
the problem. Try catching java.lang.RuntimeException instead.
> I also have the following at the top of my errors.jsp file:
>
> <%@ page isErrorPage="true" %>
That is proper procedure.
> That almost sounds like the display of the error page specified in
> web.xml won't get triggered unless the default Tomcat error page
> would have been displayed. IOW, it sort of suggests that it
> wouldn't work with errors that would not trigger the display of the
> Tomcat default error page (such as Java exceptions) I don't know
> if that is the case or not; but, it sure doesn't seem to be
> working.
No, the implementation looks conceptually like this:
try {
Servlet servlet = // get the servlet to execute
servlet.service(request, response);
// check status code, show appropriate error page defined in web.xml
} catch (RuntimeException|IOException|ServletException ex) {
Servlet errorHandler = // get error handler from web.xml or default
request.setAttribute("javax.servlet.error.exception", ex);
// and others... see SVR 10.9.1
try {
errorHandler.service(request, response);
} catch (Throwable t) {
// show default error page, guaranteed not to fail
}
}
Tomcat should be able to intercept any exception that a servlet can
legally throw. Again, java.lang.Throwable is too generic for that.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk5bxpMACgkQ9CaO5/Lv0PB7HACeLJ0psZpMC21m9dZ7o+bYbzC7
GkAAoLMDFZAVOLavQhDS703Y4DTGBv6D
=3+3P
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]