summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorwisberg <wisberg>2003-05-31 22:46:31 +0000
committerwisberg <wisberg>2003-05-31 22:46:31 +0000
commitf34c03eff62dcc70981cb8bf74a428e1ee6164d4 (patch)
treedc9e06276f286ccb8b6f48ba50d2a35f0f0f5afd /util
parentb5256c97086bbeb8dc7a61734c76c954bde2fb92 (diff)
downloadaspectj-f34c03eff62dcc70981cb8bf74a428e1ee6164d4.tar.gz
aspectj-f34c03eff62dcc70981cb8bf74a428e1ee6164d4.zip
better unwrapping of exceptions
Diffstat (limited to 'util')
-rw-r--r--util/src/org/aspectj/util/LangUtil.java43
1 files changed, 32 insertions, 11 deletions
diff --git a/util/src/org/aspectj/util/LangUtil.java b/util/src/org/aspectj/util/LangUtil.java
index 4887fda4e..8462da16d 100644
--- a/util/src/org/aspectj/util/LangUtil.java
+++ b/util/src/org/aspectj/util/LangUtil.java
@@ -14,6 +14,7 @@
package org.aspectj.util;
+import java.awt.event.InvocationEvent;
import java.io.*;
import java.io.File;
import java.io.IOException;
@@ -21,6 +22,8 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
+import java.security.PrivilegedActionException;
+import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
@@ -801,20 +804,38 @@ public class LangUtil {
/** @return Throwable input or tail of any wrapped exception chain */
public static Throwable unwrapException(Throwable t) {
- if (t instanceof InvocationTargetException) {
- Throwable thrown = ((InvocationTargetException) t).getTargetException();
- if (null != thrown) {
- return unwrapException(thrown);
+ Throwable current = t;
+ Throwable next = null;
+ while (current != null) {
+ // Java 1.2 exceptions that carry exceptions
+ if (current instanceof InvocationTargetException) {
+ next = ((InvocationTargetException) t).getTargetException();
+ } else if (t instanceof ClassNotFoundException) {
+ next = ((ClassNotFoundException) t).getException();
+ } else if (t instanceof ExceptionInInitializerError) {
+ next = ((ExceptionInInitializerError) t).getException();
+ } else if (t instanceof PrivilegedActionException) {
+ next = ((PrivilegedActionException) t).getException();
+ } else if (t instanceof SQLException) {
+ next = ((SQLException) t).getNextException();
}
- } else if (t instanceof ClassNotFoundException) {
- Throwable thrown = ((ClassNotFoundException) t).getException();
- if (null != thrown) {
- return unwrapException(thrown);
+ // ...getException():
+ // javax.naming.event.NamingExceptionEvent
+ // javax.naming.ldap.UnsolicitedNotification
+ // javax.xml.parsers.FactoryConfigurationError
+ // javax.xml.transform.TransformerFactoryConfigurationError
+ // javax.xml.transform.TransformerException
+ // org.xml.sax.SAXException
+ // 1.4: Throwable.getCause
+ // java.util.logging.LogRecord.getThrown()
+ if (null == next) {
+ break;
+ } else {
+ current = next;
+ next = null;
}
}
- // ChainedException
- // ExceptionInInitializerError
- return t;
+ return current;
}
/**