For exceptions thrown while handling a request, Spring has a number of different ways to register exception handlers. Is there a way to apply similar exception handling when the exception is thrown while rendering a view? At a minimum I’d like the ability to perform some logging.
For exceptions thrown while handling a request, Spring has a number of different ways
Share
The problem is that exceptions thrown during View rendering cannot do an awful lot. In particular, they typically can’t render a HTML page containing an error report … or even send a 5xx response … because the response will typically have “committed” before the exception is thrown.
So the best you can do (probably) is:
But the chances are that the web container can be configured to log uncaught exceptions anyway.
UPDATES
Try it and see. 🙂 But given the following, I doubt that it will work.
The chances are that the log message is actually produced using the logging subsystem. If it is, you can use the logging configuration to add your own handler for JSP engine logging events and send out special notifications.
The fact that the exceptions are 1) being thrown during JSP view rendering, and 2) the JSP engine is not propagating them means that (IMO) it is unlikely there is a way for you to catch them.
The other option is to set up a scanner for the log files … as part of your general system monitoring.