KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > lang > ExceptionInInitializerError


1 /*
2  * @(#)ExceptionInInitializerError.java 1.17 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.lang;
9
10 /**
11  * Signals that an unexpected exception has occurred in a static initializer.
12  * An <code>ExceptionInInitializerError</code> is thrown to indicate that an
13  * exception occurred during evaluation of a static initializer or the
14  * initializer for a static variable.
15  *
16  * <p>As of release 1.4, this exception has been retrofitted to conform to
17  * the general purpose exception-chaining mechanism. The "saved throwable
18  * object" that may be provided at construction time and accessed via
19  * the {@link #getException()} method is now known as the <i>cause</i>,
20  * and may be accessed via the {@link Throwable#getCause()} method, as well
21  * as the aforementioned "legacy method."
22  *
23  * @author Frank Yellin
24  * @version 1.17, 12/19/03
25  * @since JDK1.1
26  */

27 public class ExceptionInInitializerError extends LinkageError JavaDoc {
28     /**
29      * Use serialVersionUID from JDK 1.1.X for interoperability
30      */

31     private static final long serialVersionUID = 1521711792217232256L;
32
33     /**
34      * This field holds the exception if the
35      * ExceptionInInitializerError(Throwable thrown) constructor was
36      * used to instantiate the object
37      *
38      * @serial
39      *
40      */

41     private Throwable JavaDoc exception;
42
43     /**
44      * Constructs an <code>ExceptionInInitializerError</code> with
45      * <code>null</code> as its detail message string and with no saved
46      * throwable object.
47      * A detail message is a String that describes this particular exception.
48      */

49     public ExceptionInInitializerError() {
50         initCause(null); // Disallow subsequent initCause
51
}
52
53     /**
54      * Constructs a new <code>ExceptionInInitializerError</code> class by
55      * saving a reference to the <code>Throwable</code> object thrown for
56      * later retrieval by the {@link #getException()} method. The detail
57      * message string is set to <code>null</code>.
58      *
59      * @param thrown The exception thrown
60      */

61     public ExceptionInInitializerError(Throwable JavaDoc thrown) {
62         initCause(null); // Disallow subsequent initCause
63
this.exception = thrown;
64     }
65
66     /**
67      * Constructs an ExceptionInInitializerError with the specified detail
68      * message string. A detail message is a String that describes this
69      * particular exception. The detail message string is saved for later
70      * retrieval by the {@link Throwable#getMessage()} method. There is no
71      * saved throwable object.
72      *
73      *
74      * @param s the detail message
75      */

76     public ExceptionInInitializerError(String JavaDoc s) {
77     super(s);
78         initCause(null); // Disallow subsequent initCause
79
}
80
81     /**
82      * Returns the exception that occurred during a static initialization that
83      * caused this error to be created.
84      *
85      * <p>This method predates the general-purpose exception chaining facility.
86      * The {@link Throwable#getCause()} method is now the preferred means of
87      * obtaining this information.
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 JavaDoc getException() {
95     return exception;
96     }
97
98     /**
99      * Returns the cause of this error (the exception that occurred
100      * during a static initialization that caused this error to be created).
101      *
102      * @return the cause of this error or <code>null</code> if the
103      * cause is nonexistent or unknown.
104      * @since 1.4
105      */

106     public Throwable JavaDoc getCause() {
107     return exception;
108     }
109 }
110
Popular Tags