blob: ae59e9fc7f815478f0122de125224b65f4c474ef [file] [log] [blame]
Aurimas Liutikasdc3f8852024-07-11 10:07:48 -07001/*
2 * Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.lang;
27
28/**
29 * The class {@code Exception} and its subclasses are a form of
30 * {@code Throwable} that indicates conditions that a reasonable
31 * application might want to catch.
32 *
33 * <p>The class {@code Exception} and any subclasses that are not also
34 * subclasses of {@link RuntimeException} are <em>checked
35 * exceptions</em>. Checked exceptions need to be declared in a
36 * method or constructor's {@code throws} clause if they can be thrown
37 * by the execution of the method or constructor and propagate outside
38 * the method or constructor boundary.
39 *
40 * @author Frank Yellin
41 * @see java.lang.Error
42 * @jls 11.2 Compile-Time Checking of Exceptions
43 * @since 1.0
44 */
45public class Exception extends Throwable {
46 @java.io.Serial
47 static final long serialVersionUID = -3387516993124229948L;
48
49 /**
50 * Constructs a new exception with {@code null} as its detail message.
51 * The cause is not initialized, and may subsequently be initialized by a
52 * call to {@link #initCause}.
53 */
54 public Exception() {
55 super();
56 }
57
58 /**
59 * Constructs a new exception with the specified detail message. The
60 * cause is not initialized, and may subsequently be initialized by
61 * a call to {@link #initCause}.
62 *
63 * @param message the detail message. The detail message is saved for
64 * later retrieval by the {@link #getMessage()} method.
65 */
66 public Exception(String message) {
67 super(message);
68 }
69
70 /**
71 * Constructs a new exception with the specified detail message and
72 * cause. <p>Note that the detail message associated with
73 * {@code cause} is <i>not</i> automatically incorporated in
74 * this exception's detail message.
75 *
76 * @param message the detail message (which is saved for later retrieval
77 * by the {@link #getMessage()} method).
78 * @param cause the cause (which is saved for later retrieval by the
79 * {@link #getCause()} method). (A {@code null} value is
80 * permitted, and indicates that the cause is nonexistent or
81 * unknown.)
82 * @since 1.4
83 */
84 public Exception(String message, Throwable cause) {
85 super(message, cause);
86 }
87
88 /**
89 * Constructs a new exception with the specified cause and a detail
90 * message of {@code (cause==null ? null : cause.toString())} (which
91 * typically contains the class and detail message of {@code cause}).
92 * This constructor is useful for exceptions that are little more than
93 * wrappers for other throwables (for example, {@link
94 * java.security.PrivilegedActionException}).
95 *
96 * @param cause the cause (which is saved for later retrieval by the
97 * {@link #getCause()} method). (A {@code null} value is
98 * permitted, and indicates that the cause is nonexistent or
99 * unknown.)
100 * @since 1.4
101 */
102 public Exception(Throwable cause) {
103 super(cause);
104 }
105
106 /**
107 * Constructs a new exception with the specified detail message,
108 * cause, suppression enabled or disabled, and writable stack
109 * trace enabled or disabled.
110 *
111 * @param message the detail message.
112 * @param cause the cause. (A {@code null} value is permitted,
113 * and indicates that the cause is nonexistent or unknown.)
114 * @param enableSuppression whether or not suppression is enabled
115 * or disabled
116 * @param writableStackTrace whether or not the stack trace should
117 * be writable
118 * @since 1.7
119 */
120 protected Exception(String message, Throwable cause,
121 boolean enableSuppression,
122 boolean writableStackTrace) {
123 super(message, cause, enableSuppression, writableStackTrace);
124 }
125}