Catching Exceptions in Filter

"Qureshi, Affan" <[email protected]>
Newsgroups gmane.comp.java.sun.servlet
Message-ID <86190FF97874904998D905886AD505B102B72263@CHIEXVS02.corp.classifiedventures.com>
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 [email 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.