Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/lang/AssertionError.java
38829 views
/*1* Copyright (c) 2000, 2011, 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* Thrown to indicate that an assertion has failed.29*30* <p>The seven one-argument public constructors provided by this31* class ensure that the assertion error returned by the invocation:32* <pre>33* new AssertionError(<i>expression</i>)34* </pre>35* has as its detail message the <i>string conversion</i> of36* <i>expression</i> (as defined in section 15.18.1.1 of37* <cite>The Java™ Language Specification</cite>),38* regardless of the type of <i>expression</i>.39*40* @since 1.441*/42public class AssertionError extends Error {43private static final long serialVersionUID = -5013299493970297370L;4445/**46* Constructs an AssertionError with no detail message.47*/48public AssertionError() {49}5051/**52* This internal constructor does no processing on its string argument,53* even if it is a null reference. The public constructors will54* never call this constructor with a null argument.55*/56private AssertionError(String detailMessage) {57super(detailMessage);58}5960/**61* Constructs an AssertionError with its detail message derived62* from the specified object, which is converted to a string as63* defined in section 15.18.1.1 of64* <cite>The Java™ Language Specification</cite>.65*<p>66* If the specified object is an instance of {@code Throwable}, it67* becomes the <i>cause</i> of the newly constructed assertion error.68*69* @param detailMessage value to be used in constructing detail message70* @see Throwable#getCause()71*/72public AssertionError(Object detailMessage) {73this(String.valueOf(detailMessage));74if (detailMessage instanceof Throwable)75initCause((Throwable) detailMessage);76}7778/**79* Constructs an AssertionError with its detail message derived80* from the specified <code>boolean</code>, which is converted to81* a string as defined in section 15.18.1.1 of82* <cite>The Java™ Language Specification</cite>.83*84* @param detailMessage value to be used in constructing detail message85*/86public AssertionError(boolean detailMessage) {87this(String.valueOf(detailMessage));88}8990/**91* Constructs an AssertionError with its detail message derived92* from the specified <code>char</code>, which is converted to a93* string as defined in section 15.18.1.1 of94* <cite>The Java™ Language Specification</cite>.95*96* @param detailMessage value to be used in constructing detail message97*/98public AssertionError(char detailMessage) {99this(String.valueOf(detailMessage));100}101102/**103* Constructs an AssertionError with its detail message derived104* from the specified <code>int</code>, which is converted to a105* string as defined in section 15.18.1.1 of106* <cite>The Java™ Language Specification</cite>.107*108* @param detailMessage value to be used in constructing detail message109*/110public AssertionError(int detailMessage) {111this(String.valueOf(detailMessage));112}113114/**115* Constructs an AssertionError with its detail message derived116* from the specified <code>long</code>, which is converted to a117* string as defined in section 15.18.1.1 of118* <cite>The Java™ Language Specification</cite>.119*120* @param detailMessage value to be used in constructing detail message121*/122public AssertionError(long detailMessage) {123this(String.valueOf(detailMessage));124}125126/**127* Constructs an AssertionError with its detail message derived128* from the specified <code>float</code>, which is converted to a129* string as defined in section 15.18.1.1 of130* <cite>The Java™ Language Specification</cite>.131*132* @param detailMessage value to be used in constructing detail message133*/134public AssertionError(float detailMessage) {135this(String.valueOf(detailMessage));136}137138/**139* Constructs an AssertionError with its detail message derived140* from the specified <code>double</code>, which is converted to a141* string as defined in section 15.18.1.1 of142* <cite>The Java™ Language Specification</cite>.143*144* @param detailMessage value to be used in constructing detail message145*/146public AssertionError(double detailMessage) {147this(String.valueOf(detailMessage));148}149150/**151* Constructs a new {@code AssertionError} with the specified152* detail message and cause.153*154* <p>Note that the detail message associated with155* {@code cause} is <i>not</i> automatically incorporated in156* this error's detail message.157*158* @param message the detail message, may be {@code null}159* @param cause the cause, may be {@code null}160*161* @since 1.7162*/163public AssertionError(String message, Throwable cause) {164super(message, cause);165}166}167168169