jdk/src/share/classes/java/lang/ExceptionInInitializerError.java
author anthony
Tue, 05 May 2009 17:56:31 +0400
changeset 3444 18840bd1c784
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6818787: It is possible to reposition the security icon too far from the border of the window on X11 Summary: The constraints for the position of the icon are moved to the shared code Reviewed-by: art, dcherepanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1996-2000 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * Signals that an unexpected exception has occurred in a static initializer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * An <code>ExceptionInInitializerError</code> is thrown to indicate that an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * exception occurred during evaluation of a static initializer or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * initializer for a static variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <p>As of release 1.4, this exception has been retrofitted to conform to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * the general purpose exception-chaining mechanism.  The "saved throwable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * object" that may be provided at construction time and accessed via
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * the {@link #getException()} method is now known as the <i>cause</i>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * and may be accessed via the {@link Throwable#getCause()} method, as well
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * as the aforementioned "legacy method."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @author  Frank Yellin
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @since   JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class ExceptionInInitializerError extends LinkageError {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * Use serialVersionUID from JDK 1.1.X for interoperability
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static final long serialVersionUID = 1521711792217232256L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * This field holds the exception if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * ExceptionInInitializerError(Throwable thrown) constructor was
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * used to instantiate the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private Throwable exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * Constructs an <code>ExceptionInInitializerError</code> with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * <code>null</code> as its detail message string and with no saved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * throwable object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * A detail message is a String that describes this particular exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public ExceptionInInitializerError() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        initCause(null);  // Disallow subsequent initCause
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Constructs a new <code>ExceptionInInitializerError</code> class by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * saving a reference to the <code>Throwable</code> object thrown for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * later retrieval by the {@link #getException()} method. The detail
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * message string is set to <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @param thrown The exception thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public ExceptionInInitializerError(Throwable thrown) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        initCause(null);  // Disallow subsequent initCause
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        this.exception = thrown;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Constructs an ExceptionInInitializerError with the specified detail
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * message string.  A detail message is a String that describes this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * particular exception. The detail message string is saved for later
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * retrieval by the {@link Throwable#getMessage()} method. There is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * saved throwable object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param s the detail message
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public ExceptionInInitializerError(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        super(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        initCause(null);  // Disallow subsequent initCause
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * Returns the exception that occurred during a static initialization that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * caused this error to be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * <p>This method predates the general-purpose exception chaining facility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * The {@link Throwable#getCause()} method is now the preferred means of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * obtaining this information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @return the saved throwable object of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *         <code>ExceptionInInitializerError</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *         if this <code>ExceptionInInitializerError</code> has no saved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *         throwable object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public Throwable getException() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Returns the cause of this error (the exception that occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * during a static initialization that caused this error to be created).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @return  the cause of this error or <code>null</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *          cause is nonexistent or unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @since   1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public Throwable getCause() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
}