Path: blob/master/src/java.base/share/classes/java/lang/Exception.java
41152 views
/*1* Copyright (c) 1994, 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* The class {@code Exception} and its subclasses are a form of29* {@code Throwable} that indicates conditions that a reasonable30* application might want to catch.31*32* <p>The class {@code Exception} and any subclasses that are not also33* subclasses of {@link RuntimeException} are <em>checked34* exceptions</em>. Checked exceptions need to be declared in a35* method or constructor's {@code throws} clause if they can be thrown36* by the execution of the method or constructor and propagate outside37* the method or constructor boundary.38*39* @author Frank Yellin40* @see java.lang.Error41* @jls 11.2 Compile-Time Checking of Exceptions42* @since 1.043*/44public class Exception extends Throwable {45@java.io.Serial46static final long serialVersionUID = -3387516993124229948L;4748/**49* Constructs a new exception with {@code null} as its detail message.50* The cause is not initialized, and may subsequently be initialized by a51* call to {@link #initCause}.52*/53public Exception() {54super();55}5657/**58* Constructs a new exception with the specified detail message. The59* cause is not initialized, and may subsequently be initialized by60* a call to {@link #initCause}.61*62* @param message the detail message. The detail message is saved for63* later retrieval by the {@link #getMessage()} method.64*/65public Exception(String message) {66super(message);67}6869/**70* Constructs a new exception with the specified detail message and71* cause. <p>Note that the detail message associated with72* {@code cause} is <i>not</i> automatically incorporated in73* this exception's detail message.74*75* @param message the detail message (which is saved for later retrieval76* by the {@link #getMessage()} method).77* @param cause the cause (which is saved for later retrieval by the78* {@link #getCause()} method). (A {@code null} value is79* permitted, and indicates that the cause is nonexistent or80* unknown.)81* @since 1.482*/83public Exception(String message, Throwable cause) {84super(message, cause);85}8687/**88* Constructs a new exception with the specified cause and a detail89* message of {@code (cause==null ? null : cause.toString())} (which90* typically contains the class and detail message of {@code cause}).91* This constructor is useful for exceptions that are little more than92* wrappers for other throwables (for example, {@link93* java.security.PrivilegedActionException}).94*95* @param cause the cause (which is saved for later retrieval by the96* {@link #getCause()} method). (A {@code null} value is97* permitted, and indicates that the cause is nonexistent or98* unknown.)99* @since 1.4100*/101public Exception(Throwable cause) {102super(cause);103}104105/**106* Constructs a new exception with the specified detail message,107* cause, suppression enabled or disabled, and writable stack108* trace enabled or disabled.109*110* @param message the detail message.111* @param cause the cause. (A {@code null} value is permitted,112* and indicates that the cause is nonexistent or unknown.)113* @param enableSuppression whether or not suppression is enabled114* or disabled115* @param writableStackTrace whether or not the stack trace should116* be writable117* @since 1.7118*/119protected Exception(String message, Throwable cause,120boolean enableSuppression,121boolean writableStackTrace) {122super(message, cause, enableSuppression, writableStackTrace);123}124}125126127