Link to home
Start Free TrialLog in
Avatar of cgray1223
cgray1223

asked on

Servlet Container Exception Handling

Hello,

I have a J2EE application running on Tomcat 7 with log4j implemented.  I wanted to create a custom error page whenever my application encounters an Exception.  I created something similar to ex #1 below in my web.xml, but I was wondering If I can just catch all errors.  I don't think its possible since 500 is java.lang.Throwable and wont get caught if I try to use and exception-type condition (see #2 below).  

ex#1
<error-page>
    <error-code>404</error-code>
    <location>/errors/error.jsp</location>
<error-code>500</error-code>
    <location>/errors/error.jsp</location>
</error-page> 

Open in new window


ex#2
<error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/errors/error.jsp</location>  
</error-page> 

Open in new window


ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cgray1223
cgray1223

ASKER

Thanks for the response.  That would work for all exceptions I'm expecting, but not for 404s or runtime exceptions that are not trapped.  I don't think I can trap every error that could ever occur...thoughts?
Yes, I think you are right - you cannot trap every error that could ever occurs - there will be alwyas something which you had not anticipated