jtulach@258
|
1 |
/*
|
jtulach@258
|
2 |
* Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
|
jtulach@258
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
jtulach@258
|
4 |
*
|
jtulach@258
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
jtulach@258
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
jtulach@258
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
jtulach@258
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
jtulach@258
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
jtulach@258
|
10 |
*
|
jtulach@258
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
jtulach@258
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
jtulach@258
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
jtulach@258
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
jtulach@258
|
15 |
* accompanied this code).
|
jtulach@258
|
16 |
*
|
jtulach@258
|
17 |
* You should have received a copy of the GNU General Public License version
|
jtulach@258
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
jtulach@258
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
jtulach@258
|
20 |
*
|
jtulach@258
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
jtulach@258
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
jtulach@258
|
23 |
* questions.
|
jtulach@258
|
24 |
*/
|
jtulach@258
|
25 |
|
jtulach@258
|
26 |
package java.lang.reflect;
|
jtulach@258
|
27 |
|
jtulach@258
|
28 |
/**
|
jtulach@258
|
29 |
* InvocationTargetException is a checked exception that wraps
|
jtulach@258
|
30 |
* an exception thrown by an invoked method or constructor.
|
jtulach@258
|
31 |
*
|
jtulach@258
|
32 |
* <p>As of release 1.4, this exception has been retrofitted to conform to
|
jtulach@258
|
33 |
* the general purpose exception-chaining mechanism. The "target exception"
|
jtulach@258
|
34 |
* that is provided at construction time and accessed via the
|
jtulach@258
|
35 |
* {@link #getTargetException()} method is now known as the <i>cause</i>,
|
jtulach@258
|
36 |
* and may be accessed via the {@link Throwable#getCause()} method,
|
jtulach@258
|
37 |
* as well as the aforementioned "legacy method."
|
jtulach@258
|
38 |
*
|
jtulach@258
|
39 |
* @see Method
|
jtulach@258
|
40 |
* @see Constructor
|
jtulach@258
|
41 |
*/
|
jtulach@258
|
42 |
public class InvocationTargetException extends ReflectiveOperationException {
|
jtulach@258
|
43 |
/**
|
jtulach@258
|
44 |
* Use serialVersionUID from JDK 1.1.X for interoperability
|
jtulach@258
|
45 |
*/
|
jtulach@258
|
46 |
private static final long serialVersionUID = 4085088731926701167L;
|
jtulach@258
|
47 |
|
jtulach@258
|
48 |
/**
|
jtulach@258
|
49 |
* This field holds the target if the
|
jtulach@258
|
50 |
* InvocationTargetException(Throwable target) constructor was
|
jtulach@258
|
51 |
* used to instantiate the object
|
jtulach@258
|
52 |
*
|
jtulach@258
|
53 |
* @serial
|
jtulach@258
|
54 |
*
|
jtulach@258
|
55 |
*/
|
jtulach@258
|
56 |
private Throwable target;
|
jtulach@258
|
57 |
|
jtulach@258
|
58 |
/**
|
jtulach@258
|
59 |
* Constructs an {@code InvocationTargetException} with
|
jtulach@258
|
60 |
* {@code null} as the target exception.
|
jtulach@258
|
61 |
*/
|
jtulach@258
|
62 |
protected InvocationTargetException() {
|
jtulach@258
|
63 |
super((Throwable)null); // Disallow initCause
|
jtulach@258
|
64 |
}
|
jtulach@258
|
65 |
|
jtulach@258
|
66 |
/**
|
jtulach@258
|
67 |
* Constructs a InvocationTargetException with a target exception.
|
jtulach@258
|
68 |
*
|
jtulach@258
|
69 |
* @param target the target exception
|
jtulach@258
|
70 |
*/
|
jtulach@258
|
71 |
public InvocationTargetException(Throwable target) {
|
jtulach@258
|
72 |
super((Throwable)null); // Disallow initCause
|
jtulach@258
|
73 |
this.target = target;
|
jtulach@258
|
74 |
}
|
jtulach@258
|
75 |
|
jtulach@258
|
76 |
/**
|
jtulach@258
|
77 |
* Constructs a InvocationTargetException with a target exception
|
jtulach@258
|
78 |
* and a detail message.
|
jtulach@258
|
79 |
*
|
jtulach@258
|
80 |
* @param target the target exception
|
jtulach@258
|
81 |
* @param s the detail message
|
jtulach@258
|
82 |
*/
|
jtulach@258
|
83 |
public InvocationTargetException(Throwable target, String s) {
|
jtulach@258
|
84 |
super(s, null); // Disallow initCause
|
jtulach@258
|
85 |
this.target = target;
|
jtulach@258
|
86 |
}
|
jtulach@258
|
87 |
|
jtulach@258
|
88 |
/**
|
jtulach@258
|
89 |
* Get the thrown target exception.
|
jtulach@258
|
90 |
*
|
jtulach@258
|
91 |
* <p>This method predates the general-purpose exception chaining facility.
|
jtulach@258
|
92 |
* The {@link Throwable#getCause()} method is now the preferred means of
|
jtulach@258
|
93 |
* obtaining this information.
|
jtulach@258
|
94 |
*
|
jtulach@258
|
95 |
* @return the thrown target exception (cause of this exception).
|
jtulach@258
|
96 |
*/
|
jtulach@258
|
97 |
public Throwable getTargetException() {
|
jtulach@258
|
98 |
return target;
|
jtulach@258
|
99 |
}
|
jtulach@258
|
100 |
|
jtulach@258
|
101 |
/**
|
jtulach@258
|
102 |
* Returns the cause of this exception (the thrown target exception,
|
jtulach@258
|
103 |
* which may be {@code null}).
|
jtulach@258
|
104 |
*
|
jtulach@258
|
105 |
* @return the cause of this exception.
|
jtulach@258
|
106 |
* @since 1.4
|
jtulach@258
|
107 |
*/
|
jtulach@258
|
108 |
public Throwable getCause() {
|
jtulach@258
|
109 |
return target;
|
jtulach@258
|
110 |
}
|
jtulach@258
|
111 |
}
|