summaryrefslogtreecommitdiff
path: root/libjava/java/lang/reflect/InvocationTargetException.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/java/lang/reflect/InvocationTargetException.java')
-rw-r--r--libjava/java/lang/reflect/InvocationTargetException.java142
1 files changed, 63 insertions, 79 deletions
diff --git a/libjava/java/lang/reflect/InvocationTargetException.java b/libjava/java/lang/reflect/InvocationTargetException.java
index 3e7a3d32eb7..904cc631324 100644
--- a/libjava/java/lang/reflect/InvocationTargetException.java
+++ b/libjava/java/lang/reflect/InvocationTargetException.java
@@ -1,5 +1,5 @@
-/* InvocationTargetException.java - Wrapper exception for reflection
- Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+/* InvocationTargetException.java -- Wrapper exception for reflection
+ Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
-
+
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@@ -38,102 +38,86 @@ exception statement from your version. */
package java.lang.reflect;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-
-/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
- * "The Java Language Specification", ISBN 0-201-63451-1
- * Status: Believed complete and correct.
- */
-
/**
- * InvocationTargetException is sort of a way to "wrap" whatever exception
- * comes up when a method or constructor is called via Reflection.
+ * InvocationTargetException is sort of a way to "wrap" whatever exception
+ * comes up when a method or constructor is called via Reflection. As of
+ * JDK 1.4, it was retrofitted to match the exception chaining of all other
+ * exceptions, but <code>getTargetException()</code> still works.
*
* @author John Keiser
- * @version 1.1.0, 31 May 1998
* @author Tom Tromey <tromey@cygnus.com>
- * @date December 12, 1998
- *
+ * @author Eric Blake <ebb9@email.byu.edu>
* @see Method#invoke(Object,Object[])
* @see Constructor#newInstance(Object[])
+ * @since 1.1
+ * @status updated to 1.4
*/
-
-public class InvocationTargetException extends Exception
+public class InvocationTargetException extends Exception
{
- static final long serialVersionUID = 4085088731926701167L;
+ /**
+ * Compatible with JDK 1.1+.
+ */
+ private static final long serialVersionUID = 4085088731926701167L;
+
+ /**
+ * The chained exception. This field is only around for serial compatibility.
+ *
+ * @serial the chained exception
+ */
+ private final Throwable target;
- private Throwable target = null;
-
- protected InvocationTargetException()
- {
- super();
- }
-
/**
- * Create an <code>InvocationTargetException</code> using another
+ * Construct an exception with null as the cause. The cause is initialized
+ * to null.
+ */
+ protected InvocationTargetException()
+ {
+ this(null, null);
+ }
+
+ /**
+ * Create an <code>InvocationTargetException</code> using another
* exception.
+ *
* @param targetException the exception to wrap
*/
- public InvocationTargetException(Throwable targetException)
- {
- super(targetException.toString());
- target = targetException;
- }
-
- /**
- * Create an <code>InvocationTargetException</code> using another
+ public InvocationTargetException(Throwable targetException)
+ {
+ this(targetException, null);
+ }
+
+ /**
+ * Create an <code>InvocationTargetException</code> using another
* exception and an error message.
*
* @param targetException the exception to wrap
* @param err an extra reason for the exception-throwing
*/
- public InvocationTargetException(Throwable targetException, String err)
- {
- super(err);
- target = targetException;
- }
-
+ public InvocationTargetException(Throwable targetException, String err)
+ {
+ super(err, targetException);
+ target = targetException;
+ }
+
/**
* Get the wrapped (targeted) exception.
- *
- * @return the targeted exception.
+ *
+ * @return the targeted exception
+ * @see #getCause()
*/
- public Throwable getTargetException()
- {
- return target;
- }
-
- public void printStackTrace()
- {
- if (target == null)
- super.printStackTrace();
- else
- {
- System.err.print(this.getClass() + ": ");
- target.printStackTrace();
- }
- }
-
- public void printStackTrace(PrintStream ps)
- {
- if (target == null)
- super.printStackTrace(ps);
- else
- {
- ps.print(this.getClass() + ": ");
- target.printStackTrace(ps);
- }
- }
+ public Throwable getTargetException()
+ {
+ return target;
+ }
- public void printStackTrace(PrintWriter pw)
- {
- if (target == null)
- super.printStackTrace(pw);
- else
- {
- pw.print(this.getClass() + ": ");
- target.printStackTrace(pw);
- }
- }
+ /**
+ * Returns the cause of this exception (which may be null).
+ *
+ * @return the cause
+ * @since 1.4
+ */
+ public Throwable getCause()
+ {
+ return target;
+ }
}