I implemented UncaughtExceptionHandler on StartUp tomcat:
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
LOGGER.error("Uncaught Exception");
}
});
When I throw an exception in the servlet, it does not fall into my handler:
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
int i = 1/0;
The console says:
February 13, 2014 8:23:58 org.apache.catalina.core.StandardWrapperValve invoke Schwerwiegend: Servlet.service () for the [ConnectGatewaysServlet] servlet in the context of the path [/ infraview] threw an exception java.lang.ArithmeticException: / zero in net .test.gateway.ConnectGatewaysServlet.doPost (ConnectGatewaysServlet.java:73) in javax.servlet.http.HttpServlet.service (HttpServlet.java:647) in javax.servlet.http.HttpServlet.service (HttpServlet)
How to implement UncaughtExceptionHandler for a servlet?