Skip to content

Instantly share code, notes, and snippets.

@yyunikov
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yyunikov/7658a2dd46095c85cf7a to your computer and use it in GitHub Desktop.
Save yyunikov/7658a2dd46095c85cf7a to your computer and use it in GitHub Desktop.
Java: filter for handling and logging uncaught exceptions
/**
* Filter for handling and logging uncaught exceptions.
*/
@WebFilter(filterName="UncaughtExceptionFilter", urlPatterns = {"/*"})
public class UncaughtExceptionFilter implements Filter {
private static final Logger LOGGER = Logger.getLogger(UncaughtExceptionFilter.class);
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
try {
chain.doFilter(request, response);
} catch (final Throwable e) {
LOGGER.error("Uncaught Exception", e);
throw e;
}
}
@Override
public void init(FilterConfig config) throws ServletException {
}
@Override
public void destroy() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment