jaroslav@601: /* jaroslav@601: * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved. jaroslav@601: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jaroslav@601: * jaroslav@601: * This code is free software; you can redistribute it and/or modify it jaroslav@601: * under the terms of the GNU General Public License version 2 only, as jaroslav@601: * published by the Free Software Foundation. Oracle designates this jaroslav@601: * particular file as subject to the "Classpath" exception as provided jaroslav@601: * by Oracle in the LICENSE file that accompanied this code. jaroslav@601: * jaroslav@601: * This code is distributed in the hope that it will be useful, but WITHOUT jaroslav@601: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jaroslav@601: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jaroslav@601: * version 2 for more details (a copy is included in the LICENSE file that jaroslav@601: * accompanied this code). jaroslav@601: * jaroslav@601: * You should have received a copy of the GNU General Public License version jaroslav@601: * 2 along with this work; if not, write to the Free Software Foundation, jaroslav@601: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jaroslav@601: * jaroslav@601: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jaroslav@601: * or visit www.oracle.com if you need additional information or have any jaroslav@601: * questions. jaroslav@601: */ jaroslav@601: jaroslav@601: package java.lang.reflect; jaroslav@601: jaroslav@601: /** jaroslav@601: * Thrown by a method invocation on a proxy instance if its invocation jaroslav@601: * handler's {@link InvocationHandler#invoke invoke} method throws a jaroslav@601: * checked exception (a {@code Throwable} that is not assignable jaroslav@601: * to {@code RuntimeException} or {@code Error}) that jaroslav@601: * is not assignable to any of the exception types declared in the jaroslav@601: * {@code throws} clause of the method that was invoked on the jaroslav@601: * proxy instance and dispatched to the invocation handler. jaroslav@601: * jaroslav@601: *

An {@code UndeclaredThrowableException} instance contains jaroslav@601: * the undeclared checked exception that was thrown by the invocation jaroslav@601: * handler, and it can be retrieved with the jaroslav@601: * {@code getUndeclaredThrowable()} method. jaroslav@601: * {@code UndeclaredThrowableException} extends jaroslav@601: * {@code RuntimeException}, so it is an unchecked exception jaroslav@601: * that wraps a checked exception. jaroslav@601: * jaroslav@601: *

As of release 1.4, this exception has been retrofitted to jaroslav@601: * conform to the general purpose exception-chaining mechanism. The jaroslav@601: * "undeclared checked exception that was thrown by the invocation jaroslav@601: * handler" that may be provided at construction time and accessed via jaroslav@601: * the {@link #getUndeclaredThrowable()} method is now known as the jaroslav@601: * cause, and may be accessed via the {@link jaroslav@601: * Throwable#getCause()} method, as well as the aforementioned "legacy jaroslav@601: * method." jaroslav@601: * jaroslav@601: * @author Peter Jones jaroslav@601: * @see InvocationHandler jaroslav@601: * @since 1.3 jaroslav@601: */ jaroslav@601: public class UndeclaredThrowableException extends RuntimeException { jaroslav@601: static final long serialVersionUID = 330127114055056639L; jaroslav@601: jaroslav@601: /** jaroslav@601: * the undeclared checked exception that was thrown jaroslav@601: * @serial jaroslav@601: */ jaroslav@601: private Throwable undeclaredThrowable; jaroslav@601: jaroslav@601: /** jaroslav@601: * Constructs an {@code UndeclaredThrowableException} with the jaroslav@601: * specified {@code Throwable}. jaroslav@601: * jaroslav@601: * @param undeclaredThrowable the undeclared checked exception jaroslav@601: * that was thrown jaroslav@601: */ jaroslav@601: public UndeclaredThrowableException(Throwable undeclaredThrowable) { jaroslav@601: super((Throwable) null); // Disallow initCause jaroslav@601: this.undeclaredThrowable = undeclaredThrowable; jaroslav@601: } jaroslav@601: jaroslav@601: /** jaroslav@601: * Constructs an {@code UndeclaredThrowableException} with the jaroslav@601: * specified {@code Throwable} and a detail message. jaroslav@601: * jaroslav@601: * @param undeclaredThrowable the undeclared checked exception jaroslav@601: * that was thrown jaroslav@601: * @param s the detail message jaroslav@601: */ jaroslav@601: public UndeclaredThrowableException(Throwable undeclaredThrowable, jaroslav@601: String s) jaroslav@601: { jaroslav@601: super(s, null); // Disallow initCause jaroslav@601: this.undeclaredThrowable = undeclaredThrowable; jaroslav@601: } jaroslav@601: jaroslav@601: /** jaroslav@601: * Returns the {@code Throwable} instance wrapped in this jaroslav@601: * {@code UndeclaredThrowableException}, which may be {@code null}. jaroslav@601: * jaroslav@601: *

This method predates the general-purpose exception chaining facility. jaroslav@601: * The {@link Throwable#getCause()} method is now the preferred means of jaroslav@601: * obtaining this information. jaroslav@601: * jaroslav@601: * @return the undeclared checked exception that was thrown jaroslav@601: */ jaroslav@601: public Throwable getUndeclaredThrowable() { jaroslav@601: return undeclaredThrowable; jaroslav@601: } jaroslav@601: jaroslav@601: /** jaroslav@601: * Returns the cause of this exception (the {@code Throwable} jaroslav@601: * instance wrapped in this {@code UndeclaredThrowableException}, jaroslav@601: * which may be {@code null}). jaroslav@601: * jaroslav@601: * @return the cause of this exception. jaroslav@601: * @since 1.4 jaroslav@601: */ jaroslav@601: public Throwable getCause() { jaroslav@601: return undeclaredThrowable; jaroslav@601: } jaroslav@601: }