开发者

Java.lang.throwable and error codes

开发者 https://www.devze.com 2023-03-19 04:30 出处:网络
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:

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开发者_如何学Go-page>

will it be applicable for all error codes like 400,404,503,500, and i don't need to make customization for them?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号