rt/emul/mini/src/main/java/java/lang/reflect/UndeclaredThrowableException.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 26 Feb 2013 16:54:16 +0100
changeset 772 d382dacfd73f
parent 601 emul/mini/src/main/java/java/lang/reflect/UndeclaredThrowableException.java@5198affdb915
permissions -rw-r--r--
Moving modules around so the runtime is under one master pom and can be built without building other modules that are in the repository
jaroslav@601
     1
/*
jaroslav@601
     2
 * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
jaroslav@601
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jaroslav@601
     4
 *
jaroslav@601
     5
 * This code is free software; you can redistribute it and/or modify it
jaroslav@601
     6
 * under the terms of the GNU General Public License version 2 only, as
jaroslav@601
     7
 * published by the Free Software Foundation.  Oracle designates this
jaroslav@601
     8
 * particular file as subject to the "Classpath" exception as provided
jaroslav@601
     9
 * by Oracle in the LICENSE file that accompanied this code.
jaroslav@601
    10
 *
jaroslav@601
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jaroslav@601
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jaroslav@601
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jaroslav@601
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jaroslav@601
    15
 * accompanied this code).
jaroslav@601
    16
 *
jaroslav@601
    17
 * You should have received a copy of the GNU General Public License version
jaroslav@601
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jaroslav@601
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jaroslav@601
    20
 *
jaroslav@601
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jaroslav@601
    22
 * or visit www.oracle.com if you need additional information or have any
jaroslav@601
    23
 * questions.
jaroslav@601
    24
 */
jaroslav@601
    25
jaroslav@601
    26
package java.lang.reflect;
jaroslav@601
    27
jaroslav@601
    28
/**
jaroslav@601
    29
 * Thrown by a method invocation on a proxy instance if its invocation
jaroslav@601
    30
 * handler's {@link InvocationHandler#invoke invoke} method throws a
jaroslav@601
    31
 * checked exception (a {@code Throwable} that is not assignable
jaroslav@601
    32
 * to {@code RuntimeException} or {@code Error}) that
jaroslav@601
    33
 * is not assignable to any of the exception types declared in the
jaroslav@601
    34
 * {@code throws} clause of the method that was invoked on the
jaroslav@601
    35
 * proxy instance and dispatched to the invocation handler.
jaroslav@601
    36
 *
jaroslav@601
    37
 * <p>An {@code UndeclaredThrowableException} instance contains
jaroslav@601
    38
 * the undeclared checked exception that was thrown by the invocation
jaroslav@601
    39
 * handler, and it can be retrieved with the
jaroslav@601
    40
 * {@code getUndeclaredThrowable()} method.
jaroslav@601
    41
 * {@code UndeclaredThrowableException} extends
jaroslav@601
    42
 * {@code RuntimeException}, so it is an unchecked exception
jaroslav@601
    43
 * that wraps a checked exception.
jaroslav@601
    44
 *
jaroslav@601
    45
 * <p>As of release 1.4, this exception has been retrofitted to
jaroslav@601
    46
 * conform to the general purpose exception-chaining mechanism.  The
jaroslav@601
    47
 * "undeclared checked exception that was thrown by the invocation
jaroslav@601
    48
 * handler" that may be provided at construction time and accessed via
jaroslav@601
    49
 * the {@link #getUndeclaredThrowable()} method is now known as the
jaroslav@601
    50
 * <i>cause</i>, and may be accessed via the {@link
jaroslav@601
    51
 * Throwable#getCause()} method, as well as the aforementioned "legacy
jaroslav@601
    52
 * method."
jaroslav@601
    53
 *
jaroslav@601
    54
 * @author      Peter Jones
jaroslav@601
    55
 * @see         InvocationHandler
jaroslav@601
    56
 * @since       1.3
jaroslav@601
    57
 */
jaroslav@601
    58
public class UndeclaredThrowableException extends RuntimeException {
jaroslav@601
    59
    static final long serialVersionUID = 330127114055056639L;
jaroslav@601
    60
jaroslav@601
    61
    /**
jaroslav@601
    62
     * the undeclared checked exception that was thrown
jaroslav@601
    63
     * @serial
jaroslav@601
    64
     */
jaroslav@601
    65
    private Throwable undeclaredThrowable;
jaroslav@601
    66
jaroslav@601
    67
    /**
jaroslav@601
    68
     * Constructs an {@code UndeclaredThrowableException} with the
jaroslav@601
    69
     * specified {@code Throwable}.
jaroslav@601
    70
     *
jaroslav@601
    71
     * @param   undeclaredThrowable the undeclared checked exception
jaroslav@601
    72
     *          that was thrown
jaroslav@601
    73
     */
jaroslav@601
    74
    public UndeclaredThrowableException(Throwable undeclaredThrowable) {
jaroslav@601
    75
        super((Throwable) null);  // Disallow initCause
jaroslav@601
    76
        this.undeclaredThrowable = undeclaredThrowable;
jaroslav@601
    77
    }
jaroslav@601
    78
jaroslav@601
    79
    /**
jaroslav@601
    80
     * Constructs an {@code UndeclaredThrowableException} with the
jaroslav@601
    81
     * specified {@code Throwable} and a detail message.
jaroslav@601
    82
     *
jaroslav@601
    83
     * @param   undeclaredThrowable the undeclared checked exception
jaroslav@601
    84
     *          that was thrown
jaroslav@601
    85
     * @param   s the detail message
jaroslav@601
    86
     */
jaroslav@601
    87
    public UndeclaredThrowableException(Throwable undeclaredThrowable,
jaroslav@601
    88
                                        String s)
jaroslav@601
    89
    {
jaroslav@601
    90
        super(s, null);  // Disallow initCause
jaroslav@601
    91
        this.undeclaredThrowable = undeclaredThrowable;
jaroslav@601
    92
    }
jaroslav@601
    93
jaroslav@601
    94
    /**
jaroslav@601
    95
     * Returns the {@code Throwable} instance wrapped in this
jaroslav@601
    96
     * {@code UndeclaredThrowableException}, which may be {@code null}.
jaroslav@601
    97
     *
jaroslav@601
    98
     * <p>This method predates the general-purpose exception chaining facility.
jaroslav@601
    99
     * The {@link Throwable#getCause()} method is now the preferred means of
jaroslav@601
   100
     * obtaining this information.
jaroslav@601
   101
     *
jaroslav@601
   102
     * @return the undeclared checked exception that was thrown
jaroslav@601
   103
     */
jaroslav@601
   104
    public Throwable getUndeclaredThrowable() {
jaroslav@601
   105
        return undeclaredThrowable;
jaroslav@601
   106
    }
jaroslav@601
   107
jaroslav@601
   108
    /**
jaroslav@601
   109
     * Returns the cause of this exception (the {@code Throwable}
jaroslav@601
   110
     * instance wrapped in this {@code UndeclaredThrowableException},
jaroslav@601
   111
     * which may be {@code null}).
jaroslav@601
   112
     *
jaroslav@601
   113
     * @return  the cause of this exception.
jaroslav@601
   114
     * @since   1.4
jaroslav@601
   115
     */
jaroslav@601
   116
    public Throwable getCause() {
jaroslav@601
   117
        return undeclaredThrowable;
jaroslav@601
   118
    }
jaroslav@601
   119
}