2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package java.security;
21 * {@code PrivilegedActionException} wraps exceptions which are thrown from
22 * within privileged operations.
24 * Privileged actions which can throw exceptions are of type {@code
25 * PrivilegedExceptionAction} and are thrown by
27 * {@code AccessController#doPrivileged(PrivilegedExceptionAction)}<br>
28 * {@code AccessController#doPrivileged(PrivilegedExceptionAction,
29 * AccessControlContext)} </br>
32 * @see PrivilegedExceptionAction
33 * @see AccessController#doPrivileged(PrivilegedExceptionAction)
34 * @see AccessController#doPrivileged(PrivilegedExceptionAction,
35 * AccessControlContext)
37 public class PrivilegedActionException extends Exception {
39 private static final long serialVersionUID = 4724086851538908602l;
41 private Exception exception;
44 * Constructs a new instance of {@code PrivilegedActionException} with the
48 * the exception which is the cause for this exception.
50 public PrivilegedActionException(Exception ex) {
56 * Returns the exception that was thrown by a
57 * {@code PrivilegedExceptionAction}.
59 * @return the exception that was thrown by a
60 * {@code PrivilegedExceptionAction}.
62 public Exception getException() {
63 return exception; // return ( getCause() instanceof Exception ) ?
68 * Returns the exception that was thrown by a
69 * {@code PrivilegedExceptionAction}.
71 * @return the exception that was thrown by a
72 * {@code PrivilegedExceptionAction}.
75 public Throwable getCause() {
80 * Returns a string containing a concise, human-readable description of this
81 * {@code PrivilegedActionException}.
83 * @return a printable representation for this {@code
84 * PrivilegedActionException}.
87 public String toString() {
88 String s = getClass().getName();
89 return exception == null ? s : s + ": " + exception;