01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package java.lang.reflect;
19:
20: /**
21: * This class provides a wrapper for an exception thrown by a Method or
22: * Constructor invocation.
23: *
24: * @see Method#invoke
25: * @see Constructor#newInstance
26: */
27: public class InvocationTargetException extends Exception {
28:
29: private static final long serialVersionUID = 4085088731926701167L;
30:
31: private Throwable target;
32:
33: /**
34: * Constructs a new instance of this class with its walkback filled in.
35: */
36: protected InvocationTargetException() {
37: super ((Throwable) null);
38: }
39:
40: /**
41: * Constructs a new instance of this class with its walkback and target
42: * exception filled in.
43: *
44: * @param exception
45: * Throwable The exception which occurred while running the
46: * Method or Constructor.
47: */
48: public InvocationTargetException(Throwable exception) {
49: super (null, exception);
50: target = exception;
51: }
52:
53: /**
54: * Constructs a new instance of this class with its walkback, target
55: * exception and message filled in.
56: *
57: * @param detailMessage
58: * String The detail message for the exception.
59: * @param exception
60: * Throwable The exception which occurred while running the
61: * Method or Constructor.
62: */
63: public InvocationTargetException(Throwable exception,
64: String detailMessage) {
65: super (detailMessage, exception);
66: target = exception;
67: }
68:
69: /**
70: * Answers the exception which caused the receiver to be thrown.
71: */
72: public Throwable getTargetException() {
73: return target;
74: }
75:
76: /**
77: * Answers the cause of this Throwable, or null if there is no cause.
78: *
79: * @return Throwable The receiver's cause.
80: */
81: @Override
82: public Throwable getCause() {
83: return target;
84: }
85: }
|