rt/emul/compact/src/main/java/java/security/PrivilegedActionException.java
author Jaroslav Tulach <jtulach@netbeans.org>
Thu, 03 Oct 2013 15:40:35 +0200
branchjdk7-b147
changeset 1334 588d5bf7a560
permissions -rw-r--r--
Set of JDK classes needed to run javac
jtulach@1334
     1
/*
jtulach@1334
     2
 * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
jtulach@1334
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jtulach@1334
     4
 *
jtulach@1334
     5
 * This code is free software; you can redistribute it and/or modify it
jtulach@1334
     6
 * under the terms of the GNU General Public License version 2 only, as
jtulach@1334
     7
 * published by the Free Software Foundation.  Oracle designates this
jtulach@1334
     8
 * particular file as subject to the "Classpath" exception as provided
jtulach@1334
     9
 * by Oracle in the LICENSE file that accompanied this code.
jtulach@1334
    10
 *
jtulach@1334
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jtulach@1334
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jtulach@1334
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jtulach@1334
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jtulach@1334
    15
 * accompanied this code).
jtulach@1334
    16
 *
jtulach@1334
    17
 * You should have received a copy of the GNU General Public License version
jtulach@1334
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jtulach@1334
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jtulach@1334
    20
 *
jtulach@1334
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jtulach@1334
    22
 * or visit www.oracle.com if you need additional information or have any
jtulach@1334
    23
 * questions.
jtulach@1334
    24
 */
jtulach@1334
    25
jtulach@1334
    26
package java.security;
jtulach@1334
    27
jtulach@1334
    28
/**
jtulach@1334
    29
 * This exception is thrown by
jtulach@1334
    30
 * <code>doPrivileged(PrivilegedExceptionAction)</code> and
jtulach@1334
    31
 * <code>doPrivileged(PrivilegedExceptionAction,
jtulach@1334
    32
 * AccessControlContext context)</code> to indicate
jtulach@1334
    33
 * that the action being performed threw a checked exception.  The exception
jtulach@1334
    34
 * thrown by the action can be obtained by calling the
jtulach@1334
    35
 * <code>getException</code> method.  In effect, an
jtulach@1334
    36
 * <code>PrivilegedActionException</code> is a "wrapper"
jtulach@1334
    37
 * for an exception thrown by a privileged action.
jtulach@1334
    38
 *
jtulach@1334
    39
 * <p>As of release 1.4, this exception has been retrofitted to conform to
jtulach@1334
    40
 * the general purpose exception-chaining mechanism.  The "exception thrown
jtulach@1334
    41
 * by the privileged computation" that is provided at construction time and
jtulach@1334
    42
 * accessed via the {@link #getException()} method is now known as the
jtulach@1334
    43
 * <i>cause</i>, and may be accessed via the {@link Throwable#getCause()}
jtulach@1334
    44
 * method, as well as the aforementioned "legacy method."
jtulach@1334
    45
 *
jtulach@1334
    46
 * @see PrivilegedExceptionAction
jtulach@1334
    47
 * @see AccessController#doPrivileged(PrivilegedExceptionAction)
jtulach@1334
    48
 * @see AccessController#doPrivileged(PrivilegedExceptionAction,AccessControlContext)
jtulach@1334
    49
 */
jtulach@1334
    50
public class PrivilegedActionException extends Exception {
jtulach@1334
    51
    // use serialVersionUID from JDK 1.2.2 for interoperability
jtulach@1334
    52
    private static final long serialVersionUID = 4724086851538908602L;
jtulach@1334
    53
jtulach@1334
    54
    /**
jtulach@1334
    55
     * @serial
jtulach@1334
    56
     */
jtulach@1334
    57
    private Exception exception;
jtulach@1334
    58
jtulach@1334
    59
    /**
jtulach@1334
    60
     * Constructs a new PrivilegedActionException &quot;wrapping&quot;
jtulach@1334
    61
     * the specific Exception.
jtulach@1334
    62
     *
jtulach@1334
    63
     * @param exception The exception thrown
jtulach@1334
    64
     */
jtulach@1334
    65
    public PrivilegedActionException(Exception exception) {
jtulach@1334
    66
        super((Throwable)null);  // Disallow initCause
jtulach@1334
    67
        this.exception = exception;
jtulach@1334
    68
    }
jtulach@1334
    69
jtulach@1334
    70
    /**
jtulach@1334
    71
     * Returns the exception thrown by the privileged computation that
jtulach@1334
    72
     * resulted in this <code>PrivilegedActionException</code>.
jtulach@1334
    73
     *
jtulach@1334
    74
     * <p>This method predates the general-purpose exception chaining facility.
jtulach@1334
    75
     * The {@link Throwable#getCause()} method is now the preferred means of
jtulach@1334
    76
     * obtaining this information.
jtulach@1334
    77
     *
jtulach@1334
    78
     * @return the exception thrown by the privileged computation that
jtulach@1334
    79
     *         resulted in this <code>PrivilegedActionException</code>.
jtulach@1334
    80
     * @see PrivilegedExceptionAction
jtulach@1334
    81
     * @see AccessController#doPrivileged(PrivilegedExceptionAction)
jtulach@1334
    82
     * @see AccessController#doPrivileged(PrivilegedExceptionAction,
jtulach@1334
    83
     *                                            AccessControlContext)
jtulach@1334
    84
     */
jtulach@1334
    85
    public Exception getException() {
jtulach@1334
    86
        return exception;
jtulach@1334
    87
    }
jtulach@1334
    88
jtulach@1334
    89
    /**
jtulach@1334
    90
     * Returns the cause of this exception (the exception thrown by
jtulach@1334
    91
     * the privileged computation that resulted in this
jtulach@1334
    92
     * <code>PrivilegedActionException</code>).
jtulach@1334
    93
     *
jtulach@1334
    94
     * @return  the cause of this exception.
jtulach@1334
    95
     * @since   1.4
jtulach@1334
    96
     */
jtulach@1334
    97
    public Throwable getCause() {
jtulach@1334
    98
        return exception;
jtulach@1334
    99
    }
jtulach@1334
   100
jtulach@1334
   101
    public String toString() {
jtulach@1334
   102
        String s = getClass().getName();
jtulach@1334
   103
        return (exception != null) ? (s + ": " + exception.toString()) : s;
jtulach@1334
   104
    }
jtulach@1334
   105
}