0

I would like to do some custom logic anytime there is an uncaught exception in my application. Normally I would do something like:

Thread.setDefaultUncaughtExceptionHandler(myCustomHandler);

However, Thread is locked down on Google App Engine. The above code raises a security exception. Is there anyway to achieve similar functionality on Google App Engine?

EDIT: I have implemented my approach as a Servlet Filter. My experience with Java web programming is fairly limited. Can someone comment on such an approach? Since all requests in AppEngine originate as HTTP requests, I think this is a comprehensive solution.

@Override
public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain chain) throws IOException, ServletException {

    try {
        chain.doFilter(request, response);
    } catch (RuntimeException ex) {
        // Work my magic here...
        throw ex;
    }
}
Brad
  • 5,428
  • 1
  • 33
  • 56

1 Answers1

1

Servlets handle threads on their own so you should not mess with it in this way.

Instead, install a servlet Error Handler:

<error-page>
    <error-type>com.package.YourException</error-type>
    <location>/errors/handler</location>
</error-page>

then have /errors/handler map to servlet that handles the error and returns the appropriate response.

Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • Interesting approach. Is there any benefit to using this over the approach I made in my edit (or vice versa)? – Brad Jun 14 '12 at 02:37