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.