There are two main mechanisms of exception handling in Java Web Application:
Programmatically exception handling mechanism: When using try and catch block in the Java code (Servlet or Filter class) to handle exceptions.
Declarative exception handling mechanism: When using the XML tags in the web.
https://www.javatmp.com/blogs/tutorial/handle-exception-in-java-web-application