KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)UndeclaredThrowableException.java 1.13 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  * Thrown by a method invocation on a proxy instance if its invocation
12  * handler's {@link InvocationHandler#invoke invoke} method throws a
13  * checked exception (a <code>Throwable</code> that is not assignable
14  * to <code>RuntimeException</code> or <code>Error</code>) that
15  * is not assignable to any of the exception types declared in the
16  * <code>throws</code> clause of the method that was invoked on the
17  * proxy instance and dispatched to the invocation handler.
18  *
19  * <p>An <code>UndeclaredThrowableException</code> instance contains
20  * the undeclared checked exception that was thrown by the invocation
21  * handler, and it can be retrieved with the
22  * <code>getUndeclaredThrowable()</code> method.
23  * <code>UndeclaredThrowableException</code> extends
24  * <code>RuntimeException</code>, so it is an unchecked exception
25  * that wraps a checked exception.
26  *
27  * <p>As of release 1.4, this exception has been retrofitted to
28  * conform to the general purpose exception-chaining mechanism. The
29  * "undeclared checked exception that was thrown by the invocation
30  * handler" that may be provided at construction time and accessed via
31  * the {@link #getUndeclaredThrowable()} method is now known as the
32  * <i>cause</i>, and may be accessed via the {@link
33  * Throwable#getCause()} method, as well as the aforementioned "legacy
34  * method."
35  *
36  * @author Peter Jones
37  * @version 1.13, 04/02/19
38  * @see InvocationHandler
39  * @since JDK1.3
40  */

41 public class UndeclaredThrowableException extends RuntimeException JavaDoc {
42     static final long serialVersionUID = 330127114055056639L;
43
44     /**
45      * the undeclared checked exception that was thrown
46      * @serial
47      */

48     private Throwable JavaDoc undeclaredThrowable;
49
50     /**
51      * Constructs an <code>UndeclaredThrowableException</code> with the
52      * specified <code>Throwable</code>.
53      *
54      * @param undeclaredThrowable the undeclared checked exception
55      * that was thrown
56      */

57     public UndeclaredThrowableException(Throwable JavaDoc undeclaredThrowable) {
58     super((Throwable JavaDoc) null); // Disallow initCause
59
this.undeclaredThrowable = undeclaredThrowable;
60     }
61
62     /**
63      * Constructs an <code>UndeclaredThrowableException</code> with the
64      * specified <code>Throwable</code> and a detail message.
65      *
66      * @param undeclaredThrowable the undeclared checked exception
67      * that was thrown
68      * @param s the detail message
69      */

70     public UndeclaredThrowableException(Throwable JavaDoc undeclaredThrowable,
71                     String JavaDoc s)
72     {
73     super(s, null); // Disallow initCause
74
this.undeclaredThrowable = undeclaredThrowable;
75     }
76
77     /**
78      * Returns the <code>Throwable</code> instance wrapped in this
79      * <code>UndeclaredThrowableException</code>, which may be <tt>null</tt>.
80      *
81      * <p>This method predates the general-purpose exception chaining facility.
82      * The {@link Throwable#getCause()} method is now the preferred means of
83      * obtaining this information.
84      *
85      * @return the undeclared checked exception that was thrown
86      */

87     public Throwable JavaDoc getUndeclaredThrowable() {
88         return undeclaredThrowable;
89     }
90
91     /**
92      * Returns the cause of this exception (the <code>Throwable</code>
93      * instance wrapped in this <code>UndeclaredThrowableException</code>,
94      * which may be <tt>null</tt>).
95      *
96      * @return the cause of this exception.
97      * @since 1.4
98      */

99     public Throwable JavaDoc getCause() {
100         return undeclaredThrowable;
101     }
102 }
103
Popular Tags