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;
}
}
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.