1 Reply Latest reply on Mar 28, 2009 1:16 AM by Jeremy Hanna

    Exception catching logging filter

    Jeremy Hanna Newbie

      We are trying to get our Seam webapp to send out emails when there are unhandled exceptions.  We're using the java.util.logging so we are using the smtphandler sourceforge project to allow us to configure it so that severe level messages are sent out to a support/dev distribution list.


      In order to catch those unhandled exceptions, I am trying to put in a servlet filter that just catches, logs, then rethrows the exception, like so:


      public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
           try {
                chain.doFilter(request, response);
           } catch (Exception e){
                logger.severe(e.getMessage());
                throw new ServletException(e);
           }
      }



      Right now I'm just trying to get it to work.


      The problem is that even though I configure it in the web.xml and no matter where I put it in the filter-mapping ordering, it doesn't even catch the unhandled exception (I just do a

      throw new RuntimeException("Oh noooo!");

      ).  It seems that Seam is catching the exception before me.


      I tried to put in some logging into the try block and that's called.  I put a break point in the catch block but it never gets called.


      Anyway, I'm just wondering how to get to the exception before Seam does...  Any ideas?


      More info:


      Seam does catch some exceptions because of the seam filter, but I'm not doing the catch-all

      <exception>...</exception>

      without a class attribute.  So I'm just wondering why it seems to be intercepting the ones not specified in my pages.xml.

        • 1. Re: Exception catching logging filter
          Jeremy Hanna Newbie

          It looks like Seam is just catching and rethrowing exceptions that come from my app.  So the package root of the exception is org.jboss... instead of the package root of my app.


          I had been using smtphandler to catch SEVERE messages coming from my app's package root, thus missing those errors.  Now that taken out the package root qualifier, it works without a servlet filter, that is the smtphandler logs out the SEVERE messages via email now.  Disaster averted.