Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/lang/ExceptionInInitializerError.java
38829 views
/*1* Copyright (c) 1996, 2000, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.lang;2627/**28* Signals that an unexpected exception has occurred in a static initializer.29* An <code>ExceptionInInitializerError</code> is thrown to indicate that an30* exception occurred during evaluation of a static initializer or the31* initializer for a static variable.32*33* <p>As of release 1.4, this exception has been retrofitted to conform to34* the general purpose exception-chaining mechanism. The "saved throwable35* object" that may be provided at construction time and accessed via36* the {@link #getException()} method is now known as the <i>cause</i>,37* and may be accessed via the {@link Throwable#getCause()} method, as well38* as the aforementioned "legacy method."39*40* @author Frank Yellin41* @since JDK1.142*/43public class ExceptionInInitializerError extends LinkageError {44/**45* Use serialVersionUID from JDK 1.1.X for interoperability46*/47private static final long serialVersionUID = 1521711792217232256L;4849/**50* This field holds the exception if the51* ExceptionInInitializerError(Throwable thrown) constructor was52* used to instantiate the object53*54* @serial55*56*/57private Throwable exception;5859/**60* Constructs an <code>ExceptionInInitializerError</code> with61* <code>null</code> as its detail message string and with no saved62* throwable object.63* A detail message is a String that describes this particular exception.64*/65public ExceptionInInitializerError() {66initCause(null); // Disallow subsequent initCause67}6869/**70* Constructs a new <code>ExceptionInInitializerError</code> class by71* saving a reference to the <code>Throwable</code> object thrown for72* later retrieval by the {@link #getException()} method. The detail73* message string is set to <code>null</code>.74*75* @param thrown The exception thrown76*/77public ExceptionInInitializerError(Throwable thrown) {78initCause(null); // Disallow subsequent initCause79this.exception = thrown;80}8182/**83* Constructs an ExceptionInInitializerError with the specified detail84* message string. A detail message is a String that describes this85* particular exception. The detail message string is saved for later86* retrieval by the {@link Throwable#getMessage()} method. There is no87* saved throwable object.88*89*90* @param s the detail message91*/92public ExceptionInInitializerError(String s) {93super(s);94initCause(null); // Disallow subsequent initCause95}9697/**98* Returns the exception that occurred during a static initialization that99* caused this error to be created.100*101* <p>This method predates the general-purpose exception chaining facility.102* The {@link Throwable#getCause()} method is now the preferred means of103* obtaining this information.104*105* @return the saved throwable object of this106* <code>ExceptionInInitializerError</code>, or <code>null</code>107* if this <code>ExceptionInInitializerError</code> has no saved108* throwable object.109*/110public Throwable getException() {111return exception;112}113114/**115* Returns the cause of this error (the exception that occurred116* during a static initialization that caused this error to be created).117*118* @return the cause of this error or <code>null</code> if the119* cause is nonexistent or unknown.120* @since 1.4121*/122public Throwable getCause() {123return exception;124}125}126127128