[jboss-cvs] jboss-seam/src/main/org/jboss/seam/core ...

Gavin King gavin.king at jboss.com
Fri Feb 2 02:06:22 EST 2007


  User: gavin   
  Date: 07/02/02 02:06:22

  Modified:    src/main/org/jboss/seam/core  Exceptions.java
  Log:
  search exception causes for a match
  
  Revision  Changes    Path
  1.22      +18 -3     jboss-seam/src/main/org/jboss/seam/core/Exceptions.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Exceptions.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Exceptions.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -b -r1.21 -r1.22
  --- Exceptions.java	17 Dec 2006 19:46:41 -0000	1.21
  +++ Exceptions.java	2 Feb 2007 07:06:22 -0000	1.22
  @@ -27,6 +27,7 @@
   import org.jboss.seam.exceptions.AnnotationRenderHandler;
   import org.jboss.seam.log.LogProvider;
   import org.jboss.seam.log.Logging;
  +import org.jboss.seam.util.EJB;
   import org.jboss.seam.util.Reflections;
   import org.jboss.seam.util.Resources;
   import org.jboss.seam.util.Strings;
  @@ -50,13 +51,27 @@
      
      public Object handle(Exception e) throws Exception
      {
  +      //build a list of the nested exceptions
  +      List<Exception> causes = new ArrayList<Exception>();
  +      for (Exception cause=e; cause!=null; cause=EJB.getCause(cause))
  +      {
  +         causes.add(cause);
  +      }
  +      //try to match each handler in turn
         for (ExceptionHandler eh: exceptionHandlers)
         {
  -         if ( eh.isHandler(e) )
  +         //Try to handle most-nested exception before least-nested
  +         for (int i=causes.size()-1; i>=0; i--)
  +         {
  +            Exception cause = causes.get(i);
  +            if ( eh.isHandler(cause) )
            {
  -            return eh.handle(e);
  +               return eh.handle(cause);
            }
         }
  +      }
  +      
  +      //finally, rethrow it, since no handler was found
         throw e;
      }
      
  @@ -73,7 +88,7 @@
         {
            log.info("reading exceptions.xml");
            List<Element> elements = XML.getRootElement(stream).elements("exception");
  -         for (Element exception: elements)
  +         for (final Element exception: elements)
            {
               String className = exception.attributeValue("class");
               if (className==null)
  
  
  



More information about the jboss-cvs-commits mailing list