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 / lang / ExceptionInInitializerErro.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  3.9 KB  |  138 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)ExceptionInInitializerError.java    1.9 98/08/25
  3.  *
  4.  * Copyright 1996-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.lang;
  16.  
  17. import java.io.PrintStream;
  18. import java.io.PrintWriter;
  19.  
  20. /**
  21.  * Signals that an unexpected exception has occurred in a static initializer. 
  22.  * An <code>ExceptionInInitializerError</code> is thrown to indicate that an 
  23.  * exception occurred during evaluation of a static initializer or the 
  24.  * initializer for a static variable.
  25.  *
  26.  * @author  Frank Yellin
  27.  * @version 1.9, 08/25/98
  28.  *
  29.  * @since   JDK1.1
  30.  */
  31. public
  32. class ExceptionInInitializerError extends LinkageError {
  33.  
  34.     /**
  35.      * Use serialVersionUID from JDK 1.1.X for interoperability
  36.      */
  37.     private static final long serialVersionUID = 1521711792217232256L;
  38.  
  39.     /**
  40.      * This field holds the exception if the 
  41.      * ExceptionInInitializerError(Throwable thrown) constructor was
  42.      * used to instantiate the object
  43.      * 
  44.      * @serial 
  45.      * 
  46.      */
  47.     private Throwable exception;
  48.  
  49.     /**
  50.      * Constructs an <code>ExceptionInInitializerError</code> with 
  51.      * <code>null</code> as its detail message string and with no saved 
  52.      * thowable object. 
  53.      * A detail message is a String that describes this particular exception.
  54.      */
  55.     public ExceptionInInitializerError() {
  56.     super();
  57.     }
  58.  
  59.     /**
  60.      * Constructs a new <code>ExceptionInInitializerError</code> class by 
  61.      * saving a reference to the <code>Throwable</code> object thrown for 
  62.      * later retrieval by the {@link #getException()} method. The detail 
  63.      * message string is set to <code>null</code>.
  64.      *
  65.      * @param thrown The exception thrown
  66.      */
  67.     public ExceptionInInitializerError(Throwable thrown) {
  68.     this.exception = thrown;
  69.     }
  70.  
  71.     /**
  72.      * Constructs an ExceptionInInitializerError with the specified detail 
  73.      * message string.  A detail message is a String that describes this 
  74.      * particular exception. The detail message string is saved for later 
  75.      * retrieval by the {@link Throwable#getMessage()} method. There is no 
  76.      * saved throwable object. 
  77.      *
  78.      *
  79.      * @param s the detail message
  80.      */
  81.     public ExceptionInInitializerError(String s) {
  82.     super(s);
  83.     }
  84.  
  85.     /**
  86.      * Returns the exception that occurred during a static initialization that
  87.      * caused this Error to be created.
  88.      * 
  89.      * @return the saved throwable object of this 
  90.      *         <code>ExceptionInInitializerError</code>, or <code>null</code> 
  91.      *         if this <code>ExceptionInInitializerError</code> has no saved 
  92.      *         throwable object. 
  93.      */
  94.     public Throwable getException() {
  95.     return exception;
  96.     }
  97.  
  98.     /**
  99.      * Prints the stack trace of the exception that occurred.
  100.      *
  101.      * @see     java.lang.System#err
  102.      */
  103.     public void printStackTrace() {
  104.     printStackTrace(System.err);
  105.     }
  106.  
  107.     /**
  108.      * Prints the stack trace of the exception that occurred to the
  109.      * specified print stream.
  110.      */
  111.     public void printStackTrace(PrintStream ps) {
  112.     synchronized (ps) {
  113.         if (exception != null) {
  114.         ps.print("java.lang.ExceptionInInitializerError: ");
  115.         exception.printStackTrace(ps);
  116.         } else {
  117.         super.printStackTrace(ps);
  118.         }
  119.     }
  120.     }
  121.  
  122.     /**
  123.      * Prints the stack trace of the exception that occurred to the
  124.      * specified print writer.
  125.      */
  126.     public void printStackTrace(PrintWriter pw) {
  127.     synchronized (pw) {
  128.         if (exception != null) {
  129.         pw.print("java.lang.ExceptionInInitializerError: ");
  130.         exception.printStackTrace(pw);
  131.         } else {
  132.         super.printStackTrace(pw);
  133.         }
  134.     }
  135.     }
  136.  
  137. }
  138.