I have two error pages; 1 is for SpecificExceptionA and the other is for Throwable.
<error-page>
<exception-type>org.SpecificExceptionA</exception-type>
<location>/WEB-INF/views/error/timedout.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/WEB-INF/views/error/error.jsp</location>
</error-page>
If I have both of these defined in my web.xml everything goes to /error/error.jsp.
If I have just the specific exception defined, it goes to the proper page; but other errors go to the tomcat default (except 404)
Is there a better way to specify specific exception handlers? I’m using spring 3.0.
This is not specific to Tomcat. This is specific to the Servlet API. How the error page is determined is specified in chapter 9.9.2 of Servlet API specification 2.5. Here’s an extract of relevance:
So, your
SpecificExceptionAwas likely wrapped in aServletExceptionand thus thejava.lang.Throwableis the closest match on 1st pass. When you remove this entry, a 2nd pass will be made with the wrapped exception and thus yourSpecificExceptionAget a match.The right way to define a general HTTP 500 error page is to map it on
error-codeinstead ofexception-type:If this is not an option for some unclear reason, one of the ways to workaround this is to create a
Filterwhich listens on anurl-patternof/*and does basically the following:It only has to extend from
RuntimeExceptionto get it to work.