rt/emul/compact/src/main/java/java/security/PrivilegedActionException.java
branchjdk7-b147
changeset 1334 588d5bf7a560
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/rt/emul/compact/src/main/java/java/security/PrivilegedActionException.java	Thu Oct 03 15:40:35 2013 +0200
     1.3 @@ -0,0 +1,105 @@
     1.4 +/*
     1.5 + * Copyright (c) 1998, 2001, 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.security;
    1.30 +
    1.31 +/**
    1.32 + * This exception is thrown by
    1.33 + * <code>doPrivileged(PrivilegedExceptionAction)</code> and
    1.34 + * <code>doPrivileged(PrivilegedExceptionAction,
    1.35 + * AccessControlContext context)</code> to indicate
    1.36 + * that the action being performed threw a checked exception.  The exception
    1.37 + * thrown by the action can be obtained by calling the
    1.38 + * <code>getException</code> method.  In effect, an
    1.39 + * <code>PrivilegedActionException</code> is a "wrapper"
    1.40 + * for an exception thrown by a privileged action.
    1.41 + *
    1.42 + * <p>As of release 1.4, this exception has been retrofitted to conform to
    1.43 + * the general purpose exception-chaining mechanism.  The "exception thrown
    1.44 + * by the privileged computation" that is provided at construction time and
    1.45 + * accessed via the {@link #getException()} method is now known as the
    1.46 + * <i>cause</i>, and may be accessed via the {@link Throwable#getCause()}
    1.47 + * method, as well as the aforementioned "legacy method."
    1.48 + *
    1.49 + * @see PrivilegedExceptionAction
    1.50 + * @see AccessController#doPrivileged(PrivilegedExceptionAction)
    1.51 + * @see AccessController#doPrivileged(PrivilegedExceptionAction,AccessControlContext)
    1.52 + */
    1.53 +public class PrivilegedActionException extends Exception {
    1.54 +    // use serialVersionUID from JDK 1.2.2 for interoperability
    1.55 +    private static final long serialVersionUID = 4724086851538908602L;
    1.56 +
    1.57 +    /**
    1.58 +     * @serial
    1.59 +     */
    1.60 +    private Exception exception;
    1.61 +
    1.62 +    /**
    1.63 +     * Constructs a new PrivilegedActionException &quot;wrapping&quot;
    1.64 +     * the specific Exception.
    1.65 +     *
    1.66 +     * @param exception The exception thrown
    1.67 +     */
    1.68 +    public PrivilegedActionException(Exception exception) {
    1.69 +        super((Throwable)null);  // Disallow initCause
    1.70 +        this.exception = exception;
    1.71 +    }
    1.72 +
    1.73 +    /**
    1.74 +     * Returns the exception thrown by the privileged computation that
    1.75 +     * resulted in this <code>PrivilegedActionException</code>.
    1.76 +     *
    1.77 +     * <p>This method predates the general-purpose exception chaining facility.
    1.78 +     * The {@link Throwable#getCause()} method is now the preferred means of
    1.79 +     * obtaining this information.
    1.80 +     *
    1.81 +     * @return the exception thrown by the privileged computation that
    1.82 +     *         resulted in this <code>PrivilegedActionException</code>.
    1.83 +     * @see PrivilegedExceptionAction
    1.84 +     * @see AccessController#doPrivileged(PrivilegedExceptionAction)
    1.85 +     * @see AccessController#doPrivileged(PrivilegedExceptionAction,
    1.86 +     *                                            AccessControlContext)
    1.87 +     */
    1.88 +    public Exception getException() {
    1.89 +        return exception;
    1.90 +    }
    1.91 +
    1.92 +    /**
    1.93 +     * Returns the cause of this exception (the exception thrown by
    1.94 +     * the privileged computation that resulted in this
    1.95 +     * <code>PrivilegedActionException</code>).
    1.96 +     *
    1.97 +     * @return  the cause of this exception.
    1.98 +     * @since   1.4
    1.99 +     */
   1.100 +    public Throwable getCause() {
   1.101 +        return exception;
   1.102 +    }
   1.103 +
   1.104 +    public String toString() {
   1.105 +        String s = getClass().getName();
   1.106 +        return (exception != null) ? (s + ": " + exception.toString()) : s;
   1.107 +    }
   1.108 +}