Path: blob/master/src/java.base/share/classes/java/lang/Error.java
41152 views
/*1* Copyright (c) 1995, 2019, 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* An {@code Error} is a subclass of {@code Throwable}29* that indicates serious problems that a reasonable application30* should not try to catch. Most such errors are abnormal conditions.31* The {@code ThreadDeath} error, though a "normal" condition,32* is also a subclass of {@code Error} because most applications33* should not try to catch it.34* <p>35* A method is not required to declare in its {@code throws}36* clause any subclasses of {@code Error} that might be thrown37* during the execution of the method but not caught, since these38* errors are abnormal conditions that should never occur.39*40* That is, {@code Error} and its subclasses are regarded as unchecked41* exceptions for the purposes of compile-time checking of exceptions.42*43* @author Frank Yellin44* @see java.lang.ThreadDeath45* @jls 11.2 Compile-Time Checking of Exceptions46* @since 1.047*/48public class Error extends Throwable {49@java.io.Serial50static final long serialVersionUID = 4980196508277280342L;5152/**53* Constructs a new error with {@code null} as its detail message.54* The cause is not initialized, and may subsequently be initialized by a55* call to {@link #initCause}.56*/57public Error() {58super();59}6061/**62* Constructs a new error with the specified detail message. The63* cause is not initialized, and may subsequently be initialized by64* a call to {@link #initCause}.65*66* @param message the detail message. The detail message is saved for67* later retrieval by the {@link #getMessage()} method.68*/69public Error(String message) {70super(message);71}7273/**74* Constructs a new error with the specified detail message and75* cause. <p>Note that the detail message associated with76* {@code cause} is <i>not</i> automatically incorporated in77* this error's detail message.78*79* @param message the detail message (which is saved for later retrieval80* by the {@link #getMessage()} method).81* @param cause the cause (which is saved for later retrieval by the82* {@link #getCause()} method). (A {@code null} value is83* permitted, and indicates that the cause is nonexistent or84* unknown.)85* @since 1.486*/87public Error(String message, Throwable cause) {88super(message, cause);89}9091/**92* Constructs a new error with the specified cause and a detail93* message of {@code (cause==null ? null : cause.toString())} (which94* typically contains the class and detail message of {@code cause}).95* This constructor is useful for errors that are little more than96* wrappers for other throwables.97*98* @param cause the cause (which is saved for later retrieval by the99* {@link #getCause()} method). (A {@code null} value is100* permitted, and indicates that the cause is nonexistent or101* unknown.)102* @since 1.4103*/104public Error(Throwable cause) {105super(cause);106}107108/**109* Constructs a new error with the specified detail message,110* cause, suppression enabled or disabled, and writable stack111* trace enabled or disabled.112*113* @param message the detail message.114* @param cause the cause. (A {@code null} value is permitted,115* and indicates that the cause is nonexistent or unknown.)116* @param enableSuppression whether or not suppression is enabled117* or disabled118* @param writableStackTrace whether or not the stack trace should119* be writable120*121* @since 1.7122*/123protected Error(String message, Throwable cause,124boolean enableSuppression,125boolean writableStackTrace) {126super(message, cause, enableSuppression, writableStackTrace);127}128}129130131