Exceptions in Java are handled in a catch block in Try...catch, and if not handled, the exception is thrown up along the calling route, and if the page layer does not handle the exception, then the exception will be handled by the JVM. Of course it is bad to give the JVM processing, and we want to simplify the processing of exceptions, there is no simple exception handling mechanism. Of course, that's the declarative exception-handling mechanism.
The so-called declarative exception handling mechanism is the configuration in Web.xml to determine how different exception types will be processed and which page will eventually be turned to.
Let's start with the code.
<error-page>
<!--class--> <exception-type>com.tgb.drp.util.applicationexception</for exceptions
Exception-type>
<!--page-->
<location>/error.jsp</location> </When an exception occurs
Error-page>
is not very simple, in fact, many of our contact with the site is so handled
You can also configure the error number (Error-code)
<error-page>
<error-code>404</error-code>
<location>/404.html</location>
</error-page>
Declarative exceptions are simple and practical and are often used in development