jtulach@1334: /*
jtulach@1334: * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
jtulach@1334: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jtulach@1334: *
jtulach@1334: * This code is free software; you can redistribute it and/or modify it
jtulach@1334: * under the terms of the GNU General Public License version 2 only, as
jtulach@1334: * published by the Free Software Foundation. Oracle designates this
jtulach@1334: * particular file as subject to the "Classpath" exception as provided
jtulach@1334: * by Oracle in the LICENSE file that accompanied this code.
jtulach@1334: *
jtulach@1334: * This code is distributed in the hope that it will be useful, but WITHOUT
jtulach@1334: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jtulach@1334: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jtulach@1334: * version 2 for more details (a copy is included in the LICENSE file that
jtulach@1334: * accompanied this code).
jtulach@1334: *
jtulach@1334: * You should have received a copy of the GNU General Public License version
jtulach@1334: * 2 along with this work; if not, write to the Free Software Foundation,
jtulach@1334: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jtulach@1334: *
jtulach@1334: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jtulach@1334: * or visit www.oracle.com if you need additional information or have any
jtulach@1334: * questions.
jtulach@1334: */
jtulach@1334:
jtulach@1334: package java.security;
jtulach@1334:
jtulach@1334: /**
jtulach@1334: * This exception is thrown by
jtulach@1334: * doPrivileged(PrivilegedExceptionAction)
and
jtulach@1334: * doPrivileged(PrivilegedExceptionAction,
jtulach@1334: * AccessControlContext context)
to indicate
jtulach@1334: * that the action being performed threw a checked exception. The exception
jtulach@1334: * thrown by the action can be obtained by calling the
jtulach@1334: * getException
method. In effect, an
jtulach@1334: * PrivilegedActionException
is a "wrapper"
jtulach@1334: * for an exception thrown by a privileged action.
jtulach@1334: *
jtulach@1334: *
As of release 1.4, this exception has been retrofitted to conform to
jtulach@1334: * the general purpose exception-chaining mechanism. The "exception thrown
jtulach@1334: * by the privileged computation" that is provided at construction time and
jtulach@1334: * accessed via the {@link #getException()} method is now known as the
jtulach@1334: * cause, and may be accessed via the {@link Throwable#getCause()}
jtulach@1334: * method, as well as the aforementioned "legacy method."
jtulach@1334: *
jtulach@1334: * @see PrivilegedExceptionAction
jtulach@1334: * @see AccessController#doPrivileged(PrivilegedExceptionAction)
jtulach@1334: * @see AccessController#doPrivileged(PrivilegedExceptionAction,AccessControlContext)
jtulach@1334: */
jtulach@1334: public class PrivilegedActionException extends Exception {
jtulach@1334: // use serialVersionUID from JDK 1.2.2 for interoperability
jtulach@1334: private static final long serialVersionUID = 4724086851538908602L;
jtulach@1334:
jtulach@1334: /**
jtulach@1334: * @serial
jtulach@1334: */
jtulach@1334: private Exception exception;
jtulach@1334:
jtulach@1334: /**
jtulach@1334: * Constructs a new PrivilegedActionException "wrapping"
jtulach@1334: * the specific Exception.
jtulach@1334: *
jtulach@1334: * @param exception The exception thrown
jtulach@1334: */
jtulach@1334: public PrivilegedActionException(Exception exception) {
jtulach@1334: super((Throwable)null); // Disallow initCause
jtulach@1334: this.exception = exception;
jtulach@1334: }
jtulach@1334:
jtulach@1334: /**
jtulach@1334: * Returns the exception thrown by the privileged computation that
jtulach@1334: * resulted in this PrivilegedActionException
.
jtulach@1334: *
jtulach@1334: *
This method predates the general-purpose exception chaining facility.
jtulach@1334: * The {@link Throwable#getCause()} method is now the preferred means of
jtulach@1334: * obtaining this information.
jtulach@1334: *
jtulach@1334: * @return the exception thrown by the privileged computation that
jtulach@1334: * resulted in this PrivilegedActionException
.
jtulach@1334: * @see PrivilegedExceptionAction
jtulach@1334: * @see AccessController#doPrivileged(PrivilegedExceptionAction)
jtulach@1334: * @see AccessController#doPrivileged(PrivilegedExceptionAction,
jtulach@1334: * AccessControlContext)
jtulach@1334: */
jtulach@1334: public Exception getException() {
jtulach@1334: return exception;
jtulach@1334: }
jtulach@1334:
jtulach@1334: /**
jtulach@1334: * Returns the cause of this exception (the exception thrown by
jtulach@1334: * the privileged computation that resulted in this
jtulach@1334: * PrivilegedActionException
).
jtulach@1334: *
jtulach@1334: * @return the cause of this exception.
jtulach@1334: * @since 1.4
jtulach@1334: */
jtulach@1334: public Throwable getCause() {
jtulach@1334: return exception;
jtulach@1334: }
jtulach@1334:
jtulach@1334: public String toString() {
jtulach@1334: String s = getClass().getName();
jtulach@1334: return (exception != null) ? (s + ": " + exception.toString()) : s;
jtulach@1334: }
jtulach@1334: }