Catching Exceptions in Filter 2004-03-10 - By Qureshi, Affan
Back I have a strange problem when trying to catch Exceptions in my filter. I am supposed to run the chain.doFilter() method and catch any exception thereof and handle them in the Filter. But even if the Servlets throw a ServletException they are not caught in the try - catch block i have set up in the filter. However a StringIndexOutOfBoundsException is caught in that block.
My Filter.doFilter code is below:
public void doFilter(ServletRequest servletRequest, ServletResponse response, FilterChain chain) throws IOException, ServletException { String targetPage = null; boolean foundError = false;
try { logger.info(">>>>>>>>>>>> Let the servlet run ");
//let the servlet run chain.doFilter(request, response);
logger.info(">>>>>>>>>>>> In Filter.....This should not be shown ");
} catch (Exception servex) { foundError = true; logger.info(">>>>>>>>>>>> Caught exception " + servex);
//this is unhandled exception. got to system error page targetPage = systemErrorPage;
logger.error(servex.getMessage(), servex); }
}
My servlet doGet() code is simply:
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
String str = "abc"; //String def = str.substring(5,10);
if(true) throw new ServletException("ErrorMessage");
}
Any ideas?
Thanks a lot.
Affan
__ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ __ To unsubscribe, send email to listserv@(protected) and include in the body of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
|
|