KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > lang > reflect > InvocationTargetException


1 /*
2  * @(#)InvocationTargetException.java 1.19 04/02/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.lang.reflect;
9
10 /**
11  * InvocationTargetException is a checked exception that wraps
12  * an exception thrown by an invoked method or constructor.
13  *
14  * <p>As of release 1.4, this exception has been retrofitted to conform to
15  * the general purpose exception-chaining mechanism. The "target exception"
16  * that is provided at construction time and accessed via the
17  * {@link #getTargetException()} method is now known as the <i>cause</i>,
18  * and may be accessed via the {@link Throwable#getCause()} method,
19  * as well as the aforementioned "legacy method."
20  *
21  * @see Method
22  * @see Constructor
23  */

24 public class InvocationTargetException extends Exception JavaDoc {
25     /**
26      * Use serialVersionUID from JDK 1.1.X for interoperability
27      */

28     private static final long serialVersionUID = 4085088731926701167L;
29
30      /**
31      * This field holds the target if the
32      * InvocationTargetException(Throwable target) constructor was
33      * used to instantiate the object
34      *
35      * @serial
36      *
37      */

38     private Throwable JavaDoc target;
39
40     /**
41      * Constructs an <code>InvocationTargetException</code> with
42      * <code>null</code> as the target exception.
43      */

44     protected InvocationTargetException() {
45     super((Throwable JavaDoc)null); // Disallow initCause
46
}
47
48     /**
49      * Constructs a InvocationTargetException with a target exception.
50      *
51      * @param target the target exception
52      */

53     public InvocationTargetException(Throwable JavaDoc target) {
54     super((Throwable JavaDoc)null); // Disallow initCause
55
this.target = target;
56     }
57
58     /**
59      * Constructs a InvocationTargetException with a target exception
60      * and a detail message.
61      *
62      * @param target the target exception
63      * @param s the detail message
64      */

65     public InvocationTargetException(Throwable JavaDoc target, String JavaDoc s) {
66     super(s, null); // Disallow initCause
67
this.target = target;
68     }
69
70     /**
71      * Get the thrown target exception.
72      *
73      * <p>This method predates the general-purpose exception chaining facility.
74      * The {@link Throwable#getCause()} method is now the preferred means of
75      * obtaining this information.
76      *
77      * @return the thrown target exception (cause of this exception).
78      */

79     public Throwable JavaDoc getTargetException() {
80     return target;
81     }
82
83     /**
84      * Returns the cause of this exception (the thrown target exception,
85      * which may be <tt>null</tt>).
86      *
87      * @return the cause of this exception.
88      * @since 1.4
89      */

90     public Throwable JavaDoc getCause() {
91         return target;
92     }
93 }
94
Popular Tags