0

I have an unchecked exception that is not being handled by the specified web.xml error page. My directory setup is as follows:

/index.jsp

/error.jsp

/WEB-INF/web.xml

/other pages & directories here

I have the following specified in web.xml:

    <error-page>
        <exception-type>java.lang.Throwable</exception-type>
        <location>/error.jsp</location>
    </error-page>

    <error-page>
        <error-code>500</error-code>
        <location>/error.jsp</location>
    </error-page>

However, when I purposefully throw an IllegalArgumentException in my Sign In Servlet via bad object creation, the application just eats the error and logs it in the Tomcat 6.0 Log. The page is not being re-directed to error.jsp page.

What am I doing wrong? If you need more info to help, please let me know. Below is the error info from the Tomcat 6.0 Log:

SEVERE: Servlet.service() for servlet AccountSignIn threw exception java.lang.IllegalArgumentException: int id invalid in FindMeInfo.getInstance(), id: -1 at com.blank.groupandpal.FindMeInfo.getInstance(FindMeInfo.java:15) at com.blank.accounts.servs.AccountSignInServlet.processRequest(AccountSignInServlet.java:107) at com.blank.accounts.servs.AccountSignInServlet.doPost(AccountSignInServlet.java:164) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.blank.filters.SessionAuthFilter.doFilter(SessionAuthFilter.java:79) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.blank.filters.IPControlFilter.doFilter(IPControlFilter.java:97) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at ch.qos.logback.access.tomcat.LogbackValve.invoke(LogbackValve.java:158) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859) at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:574) at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1527) at java.lang.Thread.run(Thread.java:595)

Thank you.

oberger
  • 1,217
  • 2
  • 16
  • 31
  • did you try java.lang.Exception instead? – Bozho Jul 10 '11 at 20:48
  • Yes, I tried java.lang.Exception, as well as javax.servlet.ServletException. I tried all of them alone as well as in conjunction, but the error is still not bubbling up to the web.xml-defined error page. – oberger Jul 10 '11 at 20:54

1 Answers1

3

I seem to recall that the error page mechanism is disabled during the invocation of a filter's doFilter method. You might consider having an outer-most filter act as your own error page handler.

Additional info based on comment:
The error page mechanism is disabled for the request because it is being processed by one or more filters (e.g. IPControlFilter and SessionAuthFilter). It doesn't have anything to do with applying a filter to your error page. The "outer-most filter" I mentioned would be mapped to /* and would simply do something like:

try {
    chain.doFilter(request, response);
} catch (Throwable exc) {
    // set request attributes to capture error info and then forward to error page (e.g. /error.jsp)
}

In other words, this filter is essentially a recreation of the error page mechanism...

kschneid
  • 5,626
  • 23
  • 31
  • Thanks for the response! Okay, 2 questions, first is, I have a filter on the error-page, are you saying that I should make that a filter for all pages (/*) and check each request for the exception attribute? Also, is there a way to manually set the error-page during init() if the doFilter is not getting it done? – oberger Jul 14 '11 at 15:08
  • Kschneid, I tried this, but for some reason The forward in the catch portion of the block is not working. I have tried a sendRedirect and the RequestDispatcher.forward. Neither of them are working. Also, is it really true that any filtered page needs to have it's own recreated error page functionality? – oberger Jul 16 '11 at 00:46
  • I accepted that answer because I now know what I need to do, I just can't manage to implement my own error filter (recreate the functionality of the error page). – oberger Jul 16 '11 at 00:48
  • I am a moron and forgot to set my response type as appropriate considering I was calling my sign in servlet with an ajax request. thanks for the help kschneid. The error filter and page has been tested and is working fine. – oberger Jul 16 '11 at 02:19