Last active
August 29, 2015 14:08
-
-
Save yyunikov/7658a2dd46095c85cf7a to your computer and use it in GitHub Desktop.
Java: filter for handling and logging uncaught exceptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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