Reputation: 33625
i just have a question about java.lang.Throwable and does it cover all error codes i mean if i added in my web.xml:
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/serviceNotAvailable</location>
</error-page>
will it be applicable for all error codes like 400,404,503,500, and i don't need to make customization for them?
Upvotes: 1
Views: 5364
Reputation: 31371
I think you will need a mix of strategies.
Using <exception-type>java.lang.Throwable</exception-type>
will catch some (not all) of the error 500s and none of the 404s
It is therefore good practise to catch the individual errors as well as Throwables.
You can add an <error-code>
tag for each of those
<error-page>
<error-code>404</error-code>
<location>/errors/error.jsp</location>
</error-page>
You'll have to define EACH error-code individually in the web.xml.
Upvotes: 2
Reputation: 9902
An exception in your web app typically triggers a 500, so it is likely that a 500 will be handled using this strategy.
For the rest, you may not be able to encounter one of the issues with your app... but some error codes are likelier than others. And they will not be handled because they were not triggered by an unhandled exception.
Upvotes: 2