emul/mini/src/main/java/java/lang/reflect/UndeclaredThrowableException.java
branchjdk7-b147
changeset 601 5198affdb915
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/emul/mini/src/main/java/java/lang/reflect/UndeclaredThrowableException.java	Mon Jan 28 18:12:47 2013 +0100
     1.3 @@ -0,0 +1,119 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package java.lang.reflect;
    1.30 +
    1.31 +/**
    1.32 + * Thrown by a method invocation on a proxy instance if its invocation
    1.33 + * handler's {@link InvocationHandler#invoke invoke} method throws a
    1.34 + * checked exception (a {@code Throwable} that is not assignable
    1.35 + * to {@code RuntimeException} or {@code Error}) that
    1.36 + * is not assignable to any of the exception types declared in the
    1.37 + * {@code throws} clause of the method that was invoked on the
    1.38 + * proxy instance and dispatched to the invocation handler.
    1.39 + *
    1.40 + * <p>An {@code UndeclaredThrowableException} instance contains
    1.41 + * the undeclared checked exception that was thrown by the invocation
    1.42 + * handler, and it can be retrieved with the
    1.43 + * {@code getUndeclaredThrowable()} method.
    1.44 + * {@code UndeclaredThrowableException} extends
    1.45 + * {@code RuntimeException}, so it is an unchecked exception
    1.46 + * that wraps a checked exception.
    1.47 + *
    1.48 + * <p>As of release 1.4, this exception has been retrofitted to
    1.49 + * conform to the general purpose exception-chaining mechanism.  The
    1.50 + * "undeclared checked exception that was thrown by the invocation
    1.51 + * handler" that may be provided at construction time and accessed via
    1.52 + * the {@link #getUndeclaredThrowable()} method is now known as the
    1.53 + * <i>cause</i>, and may be accessed via the {@link
    1.54 + * Throwable#getCause()} method, as well as the aforementioned "legacy
    1.55 + * method."
    1.56 + *
    1.57 + * @author      Peter Jones
    1.58 + * @see         InvocationHandler
    1.59 + * @since       1.3
    1.60 + */
    1.61 +public class UndeclaredThrowableException extends RuntimeException {
    1.62 +    static final long serialVersionUID = 330127114055056639L;
    1.63 +
    1.64 +    /**
    1.65 +     * the undeclared checked exception that was thrown
    1.66 +     * @serial
    1.67 +     */
    1.68 +    private Throwable undeclaredThrowable;
    1.69 +
    1.70 +    /**
    1.71 +     * Constructs an {@code UndeclaredThrowableException} with the
    1.72 +     * specified {@code Throwable}.
    1.73 +     *
    1.74 +     * @param   undeclaredThrowable the undeclared checked exception
    1.75 +     *          that was thrown
    1.76 +     */
    1.77 +    public UndeclaredThrowableException(Throwable undeclaredThrowable) {
    1.78 +        super((Throwable) null);  // Disallow initCause
    1.79 +        this.undeclaredThrowable = undeclaredThrowable;
    1.80 +    }
    1.81 +
    1.82 +    /**
    1.83 +     * Constructs an {@code UndeclaredThrowableException} with the
    1.84 +     * specified {@code Throwable} and a detail message.
    1.85 +     *
    1.86 +     * @param   undeclaredThrowable the undeclared checked exception
    1.87 +     *          that was thrown
    1.88 +     * @param   s the detail message
    1.89 +     */
    1.90 +    public UndeclaredThrowableException(Throwable undeclaredThrowable,
    1.91 +                                        String s)
    1.92 +    {
    1.93 +        super(s, null);  // Disallow initCause
    1.94 +        this.undeclaredThrowable = undeclaredThrowable;
    1.95 +    }
    1.96 +
    1.97 +    /**
    1.98 +     * Returns the {@code Throwable} instance wrapped in this
    1.99 +     * {@code UndeclaredThrowableException}, which may be {@code null}.
   1.100 +     *
   1.101 +     * <p>This method predates the general-purpose exception chaining facility.
   1.102 +     * The {@link Throwable#getCause()} method is now the preferred means of
   1.103 +     * obtaining this information.
   1.104 +     *
   1.105 +     * @return the undeclared checked exception that was thrown
   1.106 +     */
   1.107 +    public Throwable getUndeclaredThrowable() {
   1.108 +        return undeclaredThrowable;
   1.109 +    }
   1.110 +
   1.111 +    /**
   1.112 +     * Returns the cause of this exception (the {@code Throwable}
   1.113 +     * instance wrapped in this {@code UndeclaredThrowableException},
   1.114 +     * which may be {@code null}).
   1.115 +     *
   1.116 +     * @return  the cause of this exception.
   1.117 +     * @since   1.4
   1.118 +     */
   1.119 +    public Throwable getCause() {
   1.120 +        return undeclaredThrowable;
   1.121 +    }
   1.122 +}