[PATCH] DefinitionException swallows exception

"Vincent Massol" <[email protected]>
Newsgroups gmane.comp.java.aspectwerkz.devel
Message-ID <01c201c3cb02$873d4ae0$2502a8c0@vma>
Hi,

The current implementation of DefinitionException swallows exception.
Thus when a stack trace is printed, knowing the reason of the error is
extremely difficult (if not outright impossible). Here's a patch to
prevent this.

Thanks

PS: the patch might be difficult to apply due to the extra lines problem
I mentioned in an earlier email.

-Vincent
Wanna see JUnit in Action?
(http://manning.com/massol)
definitionexception.patch (application/octet-stream, 3.5 KB)
Index: org/codehaus/aspectwerkz/exception/DefinitionException.java
===================================================================
retrieving revision 1.9
diff -u -r1.9 DefinitionException.java
--- org/codehaus/aspectwerkz/exception/DefinitionException.java	12 Dec 2003 15:17:08 -0000	1.9
+++ org/codehaus/aspectwerkz/exception/DefinitionException.java	25 Dec 2003 16:28:33 -0000
@@ -5,15 +5,15 @@
  * The software in this package is published under the terms of the QPL license       *
  * a copy of which has been included with this distribution in the license.txt file.  *
  **************************************************************************************/
-package org.codehaus.aspectwerkz.exception;
+package org.codehaus.aspectwerkz.exception;

import java.io.PrintStream;
import java.io.PrintWriter;
 
 /**
  * Thrown when error in definition.
  *
- * @author <a href="mailto:jboner-yCVjj/[email protected]">Jonas Bonér</a>
+ * @author <a href="mailto:jboner-yCVjj/[email protected]">Jonas Bonér</a>
 * @author <a href="mailto:[email protected]">Vincent Massol</a>
  */
 public class DefinitionException extends RuntimeException {
-
+    /**
     * Original exception which caused this exception.
     */
    private Throwable originalException;
    
     /**
      * Sets the message for the exception.
      *
@@ -21,5 +21,5 @@
      */
     public DefinitionException(final String message) {
         super(message);
-    }
-}
+    }

    /**
     * Sets the message for the exception and the original exception being
     * wrapped.
     *
     * @param message the detail of the error message
     * @param throwable the original exception
     */
    public DefinitionException(String message, Throwable throwable)
    {
        super(message);
        this.originalException = throwable;
    }
    
+    /**
     * Print the full stack trace, including the original exception.
     */
    public void printStackTrace() {
        
        printStackTrace(System.err);
    }

    /**
     * Print the full stack trace, including the original exception.
     *
     * @param ps the byte stream in which to print the stack trace
     */
    public void printStackTrace(PrintStream ps) {
        
        super.printStackTrace(ps);

        if (this.originalException != null) {
            this.originalException.printStackTrace(ps);
        }
    }

    /**
     * Print the full stack trace, including the original exception.
     *
     * @param pw the character stream in which to print the stack trace
     */
    public void printStackTrace(PrintWriter pw) {
        
        super.printStackTrace(pw);

        if (this.originalException != null) {
            this.originalException.printStackTrace(pw);
        }
    }

}
\ No newline at end of file
Index: org/codehaus/aspectwerkz/regexp/ClassPattern.java
===================================================================
retrieving revision 1.13
diff -u -r1.13 ClassPattern.java
--- org/codehaus/aspectwerkz/regexp/ClassPattern.java	12 Dec 2003 15:17:08 -0000	1.13
+++ org/codehaus/aspectwerkz/regexp/ClassPattern.java	25 Dec 2003 16:28:34 -0000
@@ -78,7 +78,7 @@
             m_classNamePattern = new com.karneim.util.collection.regex.Pattern(className);
         }
         catch (Throwable e) {
-            throw new DefinitionException("class pattern is not well formed: " + pattern);
+            throw new DefinitionException("class pattern is not well formed: " + pattern, e);
         }
     }
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.