KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > security > PrivilegedActionException


1 /*
2  * @(#)PrivilegedActionException.java 1.16 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.security;
9
10 /**
11  * This exception is thrown by
12  * <code>doPrivileged(PrivilegedExceptionAction)</code> and
13  * <code>doPrivileged(PrivilegedExceptionAction,
14  * AccessControlContext context)</code> to indicate
15  * that the action being performed threw a checked exception. The exception
16  * thrown by the action can be obtained by calling the
17  * <code>getException</code> method. In effect, an
18  * <code>PrivilegedActionException</code> is a "wrapper"
19  * for an exception thrown by a privileged action.
20  *
21  * <p>As of release 1.4, this exception has been retrofitted to conform to
22  * the general purpose exception-chaining mechanism. The "exception thrown
23  * by the privileged computation" that is provided at construction time and
24  * accessed via the {@link #getException()} method is now known as the
25  * <i>cause</i>, and may be accessed via the {@link Throwable#getCause()}
26  * method, as well as the aforementioned "legacy method."
27  *
28  * @see PrivilegedExceptionAction
29  * @see AccessController#doPrivileged(PrivilegedExceptionAction)
30  * @see AccessController#doPrivileged(PrivilegedExceptionAction,AccessControlContext)
31  */

32 public class PrivilegedActionException extends Exception JavaDoc {
33     // use serialVersionUID from JDK 1.2.2 for interoperability
34
private static final long serialVersionUID = 4724086851538908602L;
35
36     /**
37      * @serial
38      */

39     private Exception JavaDoc exception;
40
41     /**
42      * Constructs a new PrivilegedActionException &quot;wrapping&quot;
43      * the specific Exception.
44      *
45      * @param exception The exception thrown
46      */

47     public PrivilegedActionException(Exception JavaDoc exception) {
48     super((Throwable JavaDoc)null); // Disallow initCause
49
this.exception = exception;
50     }
51
52     /**
53      * Returns the exception thrown by the privileged computation that
54      * resulted in this <code>PrivilegedActionException</code>.
55      *
56      * <p>This method predates the general-purpose exception chaining facility.
57      * The {@link Throwable#getCause()} method is now the preferred means of
58      * obtaining this information.
59      *
60      * @return the exception thrown by the privileged computation that
61      * resulted in this <code>PrivilegedActionException</code>.
62      * @see PrivilegedExceptionAction
63      * @see AccessController#doPrivileged(PrivilegedExceptionAction)
64      * @see AccessController#doPrivileged(PrivilegedExceptionAction,
65      * AccessControlContext)
66      */

67     public Exception JavaDoc getException() {
68     return exception;
69     }
70
71     /**
72      * Returns the the cause of this exception (the exception thrown by
73      * the privileged computation that resulted in this
74      * <code>PrivilegedActionException</code>).
75      *
76      * @return the cause of this exception.
77      * @since 1.4
78      */

79     public Throwable JavaDoc getCause() {
80         return exception;
81     }
82
83     public String JavaDoc toString() {
84         String JavaDoc s = getClass().getName();
85         return (exception != null) ? (s + ": " + exception.toString()) : s;
86     }
87 }
88
Popular Tags