Declarative Exception Handling Mechanism

Source: Internet
Author: User

Exceptions in java are all in try... if the catch Block is not processed, the exception will be thrown along the call route. If the page layer does not handle the exception, the exception will be handled by JVM. Of course, it is very difficult to handle exceptions by JVM. But we want to simplify Exception Handling. Is there a simple exception handling mechanism? Of course, there is a declarative exception handling mechanism.

The so-called declarative Exception Handling Mechanism is to determine in web. xml how different exception types will be handled through configuration, and finally to which page.

Run the code first.


[Html]
<Error-page>
<! -- Abnormal class -->
<Exception-type> com. tgb. drp. util. ApplicationException </exception-type>
<! -- Page for turning when an exception occurs -->
<Location>/error. jsp </location>
 
</Error-page>

<Error-page>
<! -- Abnormal class -->
<Exception-type> com. tgb. drp. util. ApplicationException </exception-type>
<! -- Page for turning when an exception occurs -->
<Location>/error. jsp </location>

</Error-page>


Is it very simple? In fact, many of the websites we contact are handled in this way.

 


You can also configure the error code)


[Html]
<Error-page>
<Error-code> 404 </error-code>
<Location>/404.html </location>
</Error-page>

<Error-page>
<Error-code> 404 </error-code>
<Location>/404.html </location>
</Error-page>
Declarative exceptions are simple and practical, and are often used during development.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.