2 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
29 * Thrown to indicate that an assertion has failed.
31 * <p>The seven one-argument public constructors provided by this
32 * class ensure that the assertion error returned by the invocation:
34 * new AssertionError(<i>expression</i>)
36 * has as its detail message the <i>string conversion</i> of
37 * <i>expression</i> (as defined in section 15.18.1.1 of
38 * <cite>The Java™ Language Specification</cite>),
39 * regardless of the type of <i>expression</i>.
43 public class AssertionError extends Error {
44 private static final long serialVersionUID = -5013299493970297370L;
47 * Constructs an AssertionError with no detail message.
49 public AssertionError() {
53 * This internal constructor does no processing on its string argument,
54 * even if it is a null reference. The public constructors will
55 * never call this constructor with a null argument.
57 private AssertionError(String detailMessage) {
62 * Constructs an AssertionError with its detail message derived
63 * from the specified object, which is converted to a string as
64 * defined in section 15.18.1.1 of
65 * <cite>The Java™ Language Specification</cite>.
67 * If the specified object is an instance of {@code Throwable}, it
68 * becomes the <i>cause</i> of the newly constructed assertion error.
70 * @param detailMessage value to be used in constructing detail message
71 * @see Throwable#getCause()
73 public AssertionError(Object detailMessage) {
74 this("" + detailMessage);
75 if (detailMessage instanceof Throwable)
76 initCause((Throwable) detailMessage);
80 * Constructs an AssertionError with its detail message derived
81 * from the specified <code>boolean</code>, which is converted to
82 * a string as defined in section 15.18.1.1 of
83 * <cite>The Java™ Language Specification</cite>.
85 * @param detailMessage value to be used in constructing detail message
87 public AssertionError(boolean detailMessage) {
88 this("" + detailMessage);
92 * Constructs an AssertionError with its detail message derived
93 * from the specified <code>char</code>, which is converted to a
94 * string as defined in section 15.18.1.1 of
95 * <cite>The Java™ Language Specification</cite>.
97 * @param detailMessage value to be used in constructing detail message
99 public AssertionError(char detailMessage) {
100 this("" + detailMessage);
104 * Constructs an AssertionError with its detail message derived
105 * from the specified <code>int</code>, which is converted to a
106 * string as defined in section 15.18.1.1 of
107 * <cite>The Java™ Language Specification</cite>.
109 * @param detailMessage value to be used in constructing detail message
111 public AssertionError(int detailMessage) {
112 this("" + detailMessage);
116 * Constructs an AssertionError with its detail message derived
117 * from the specified <code>long</code>, which is converted to a
118 * string as defined in section 15.18.1.1 of
119 * <cite>The Java™ Language Specification</cite>.
121 * @param detailMessage value to be used in constructing detail message
123 public AssertionError(long detailMessage) {
124 this("" + detailMessage);
128 * Constructs an AssertionError with its detail message derived
129 * from the specified <code>float</code>, which is converted to a
130 * string as defined in section 15.18.1.1 of
131 * <cite>The Java™ Language Specification</cite>.
133 * @param detailMessage value to be used in constructing detail message
135 public AssertionError(float detailMessage) {
136 this("" + detailMessage);
140 * Constructs an AssertionError with its detail message derived
141 * from the specified <code>double</code>, which is converted to a
142 * string as defined in section 15.18.1.1 of
143 * <cite>The Java™ Language Specification</cite>.
145 * @param detailMessage value to be used in constructing detail message
147 public AssertionError(double detailMessage) {
148 this("" + detailMessage);
152 * Constructs a new {@code AssertionError} with the specified
153 * detail message and cause.
155 * <p>Note that the detail message associated with
156 * {@code cause} is <i>not</i> automatically incorporated in
157 * this error's detail message.
159 * @param message the detail message, may be {@code null}
160 * @param cause the cause, may be {@code null}
164 public AssertionError(String message, Throwable cause) {
165 super(message, cause);