1 /*
2  * Copyright (c) 1995, 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 
26 package java.lang;
27 
28 /**
29  * {@code RuntimeException} is the superclass of those
30  * exceptions that can be thrown during the normal operation of the
31  * Java Virtual Machine.
32  *
33  * <p>{@code RuntimeException} and its subclasses are <em>unchecked
34  * exceptions</em>.  Unchecked exceptions do <em>not</em> need to be
35  * declared in a method or constructor's {@code throws} clause if they
36  * can be thrown by the execution of the method or constructor and
37  * propagate outside the method or constructor boundary.
38  *
39  * @author  Frank Yellin
40  * @jls 11.2 Compile-Time Checking of Exceptions
41  * @since   1.0
42  */
43 public class RuntimeException extends Exception {
44     @java.io.Serial
45     static final long serialVersionUID = -7034897190745766939L;
46 
47     /** Constructs a new runtime exception with {@code null} as its
48      * detail message.  The cause is not initialized, and may subsequently be
49      * initialized by a call to {@link #initCause}.
50      */
RuntimeException()51     public RuntimeException() {
52         super();
53     }
54 
55     /** Constructs a new runtime exception with the specified detail message.
56      * The cause is not initialized, and may subsequently be initialized by a
57      * call to {@link #initCause}.
58      *
59      * @param   message   the detail message. The detail message is saved for
60      *          later retrieval by the {@link #getMessage()} method.
61      */
RuntimeException(String message)62     public RuntimeException(String message) {
63         super(message);
64     }
65 
66     /**
67      * Constructs a new runtime exception with the specified detail message and
68      * cause.  <p>Note that the detail message associated with
69      * {@code cause} is <i>not</i> automatically incorporated in
70      * this runtime exception's detail message.
71      *
72      * @param  message the detail message (which is saved for later retrieval
73      *         by the {@link #getMessage()} method).
74      * @param  cause the cause (which is saved for later retrieval by the
75      *         {@link #getCause()} method).  (A {@code null} value is
76      *         permitted, and indicates that the cause is nonexistent or
77      *         unknown.)
78      * @since  1.4
79      */
RuntimeException(String message, Throwable cause)80     public RuntimeException(String message, Throwable cause) {
81         super(message, cause);
82     }
83 
84     /** Constructs a new runtime exception with the specified cause and a
85      * detail message of {@code (cause==null ? null : cause.toString())}
86      * (which typically contains the class and detail message of
87      * {@code cause}).  This constructor is useful for runtime exceptions
88      * that are little more than wrappers for other throwables.
89      *
90      * @param  cause the cause (which is saved for later retrieval by the
91      *         {@link #getCause()} method).  (A {@code null} value is
92      *         permitted, and indicates that the cause is nonexistent or
93      *         unknown.)
94      * @since  1.4
95      */
RuntimeException(Throwable cause)96     public RuntimeException(Throwable cause) {
97         super(cause);
98     }
99 
100     /**
101      * Constructs a new runtime exception with the specified detail
102      * message, cause, suppression enabled or disabled, and writable
103      * stack trace enabled or disabled.
104      *
105      * @param  message the detail message.
106      * @param cause the cause.  (A {@code null} value is permitted,
107      * and indicates that the cause is nonexistent or unknown.)
108      * @param enableSuppression whether or not suppression is enabled
109      *                          or disabled
110      * @param writableStackTrace whether or not the stack trace should
111      *                           be writable
112      *
113      * @since 1.7
114      */
RuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace)115     protected RuntimeException(String message, Throwable cause,
116                                boolean enableSuppression,
117                                boolean writableStackTrace) {
118         super(message, cause, enableSuppression, writableStackTrace);
119     }
120 }
121