home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / security / PrivilegedActionException.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  3.1 KB  |  107 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)PrivilegedActionException.java    1.3 98/06/29
  3.  *
  4.  * Copyright 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.security;
  16.  
  17. import java.io.PrintWriter;
  18. import java.io.PrintStream;
  19.  
  20.  
  21. /**
  22.  * This exception is thrown by
  23.  * <code>doPrivileged(PrivilegedExceptionAction)</code> and
  24.  * <code>doPrivileged(PrivilegedExceptionAction,
  25.  * AccessControlContext context)</code> to indicate
  26.  * that the action being performed threw a checked exception.  The exception
  27.  * thrown by the action can be obtained by calling the
  28.  * <code>getException</code> method.  In effect, an
  29.  * <code>PrivilegedActionException</code> is a "wrapper"
  30.  * for an exception thrown by a privileged action.
  31.  *
  32.  * @see PrivilegedExceptionAction
  33.  * @see AccessController#doPrivileged(PrivilegedExceptionAction)
  34.  * @see AccessController#doPrivileged(PrivilegedExceptionAction,AccessControlContext)
  35.  */
  36. public
  37. class PrivilegedActionException extends Exception {
  38.     /**
  39.      * @serial
  40.      */
  41.     private Exception exception;
  42.  
  43.     /**
  44.      * Constructs a new PrivilegedActionException "wrapping"
  45.      * the specific Exception
  46.      *
  47.      * @param exception The exception thrown
  48.      */
  49.     public PrivilegedActionException(Exception exception) {
  50.     this.exception = exception;
  51.     }
  52.  
  53.     /**
  54.      * Returns the exception thrown by the privileged computation that
  55.      * resulted in this <code>PrivilegedActionException</code>.
  56.      *
  57.      * @return the exception thrown by the privileged computation that
  58.      *         resulted in this <code>PrivilegedActionException</code>.
  59.      * @see PrivilegedExceptionAction
  60.      * @see AccessController#doPrivileged(PrivilegedExceptionAction)
  61.      * @see AccessController#doPrivileged(PrivilegedExceptionAction,
  62.      *                                            AccessControlContext)
  63.      */
  64.     public Exception getException() {
  65.     return exception;
  66.     }
  67.  
  68.     /**
  69.      * Prints the stack trace of the exception that occurred.
  70.      *
  71.      * @see     java.lang.System#err
  72.      */
  73.     public void printStackTrace() {
  74.     printStackTrace(System.err);
  75.     }
  76.  
  77.     /**
  78.      * Prints the stack trace of the exception that occurred to the
  79.      * specified print stream.
  80.      */
  81.     public void printStackTrace(PrintStream ps) {
  82.     synchronized (ps) {
  83.         if (exception != null) {
  84.         ps.print("java.security.PrivilegedActionException: ");
  85.         exception.printStackTrace(ps);
  86.         } else {
  87.         super.printStackTrace(ps);
  88.         }
  89.     }
  90.     }
  91.  
  92.     /**
  93.      * Prints the stack trace of the exception that occurred to the
  94.      * specified print writer.
  95.      */
  96.     public void printStackTrace(PrintWriter pw) {
  97.     synchronized (pw) {
  98.         if (exception != null) {
  99.         pw.print("java.security.PrivilegedActionException: ");
  100.         exception.printStackTrace(pw);
  101.         } else {
  102.         super.printStackTrace(pw);
  103.         }
  104.     }
  105.     }
  106. }
  107.