OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / main / java / java / security / PrivilegedActionException.java
1 /*
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 package java.security;
19
20 /**
21  * {@code PrivilegedActionException} wraps exceptions which are thrown from
22  * within privileged operations.
23  * <p>
24  * Privileged actions which can throw exceptions are of type {@code
25  * PrivilegedExceptionAction} and are thrown by
26  * <ul>
27  * {@code AccessController#doPrivileged(PrivilegedExceptionAction)}<br>
28  * {@code AccessController#doPrivileged(PrivilegedExceptionAction,
29  * AccessControlContext)} </br>
30  * </ul>
31  *
32  * @see PrivilegedExceptionAction
33  * @see AccessController#doPrivileged(PrivilegedExceptionAction)
34  * @see AccessController#doPrivileged(PrivilegedExceptionAction,
35  *      AccessControlContext)
36  */
37 public class PrivilegedActionException extends Exception {
38
39     private static final long serialVersionUID = 4724086851538908602l;
40
41     private Exception exception;
42
43     /**
44      * Constructs a new instance of {@code PrivilegedActionException} with the
45      * cause.
46      *
47      * @param ex
48      *            the exception which is the cause for this exception.
49      */
50     public PrivilegedActionException(Exception ex) {
51         super(ex);
52         this.exception = ex;
53     }
54
55     /**
56      * Returns the exception that was thrown by a
57      * {@code PrivilegedExceptionAction}.
58      *
59      * @return the exception that was thrown by a
60      *         {@code PrivilegedExceptionAction}.
61      */
62     public Exception getException() {
63         return exception; // return ( getCause() instanceof Exception ) ?
64         // getCause() : null;
65     }
66
67     /**
68      * Returns the exception that was thrown by a
69      * {@code PrivilegedExceptionAction}.
70      *
71      * @return the exception that was thrown by a
72      *         {@code PrivilegedExceptionAction}.
73      */
74     @Override
75     public Throwable getCause() {
76         return exception;
77     }
78
79     /**
80      * Returns a string containing a concise, human-readable description of this
81      * {@code PrivilegedActionException}.
82      *
83      * @return a printable representation for this {@code
84      *         PrivilegedActionException}.
85      */
86     @Override
87     public String toString() {
88         String s = getClass().getName();
89         return exception == null ? s : s + ": " + exception;
90     }
91
92 }