jaroslav@70: /* jaroslav@70: * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. jaroslav@70: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jaroslav@70: * jaroslav@70: * This code is free software; you can redistribute it and/or modify it jaroslav@70: * under the terms of the GNU General Public License version 2 only, as jaroslav@70: * published by the Free Software Foundation. Oracle designates this jaroslav@70: * particular file as subject to the "Classpath" exception as provided jaroslav@70: * by Oracle in the LICENSE file that accompanied this code. jaroslav@70: * jaroslav@70: * This code is distributed in the hope that it will be useful, but WITHOUT jaroslav@70: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jaroslav@70: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jaroslav@70: * version 2 for more details (a copy is included in the LICENSE file that jaroslav@70: * accompanied this code). jaroslav@70: * jaroslav@70: * You should have received a copy of the GNU General Public License version jaroslav@70: * 2 along with this work; if not, write to the Free Software Foundation, jaroslav@70: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jaroslav@70: * jaroslav@70: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jaroslav@70: * or visit www.oracle.com if you need additional information or have any jaroslav@70: * questions. jaroslav@70: */ jaroslav@70: jaroslav@70: package java.lang; jaroslav@70: jaroslav@70: /** jaroslav@70: * Thrown to indicate that an assertion has failed. jaroslav@70: * jaroslav@70: *

The seven one-argument public constructors provided by this jaroslav@70: * class ensure that the assertion error returned by the invocation: jaroslav@70: *

jaroslav@70:  *     new AssertionError(expression)
jaroslav@70:  * 
jaroslav@70: * has as its detail message the string conversion of jaroslav@70: * expression (as defined in section 15.18.1.1 of jaroslav@70: * The Java™ Language Specification), jaroslav@70: * regardless of the type of expression. jaroslav@70: * jaroslav@70: * @since 1.4 jaroslav@70: */ jaroslav@70: public class AssertionError extends Error { jaroslav@70: private static final long serialVersionUID = -5013299493970297370L; jaroslav@70: jaroslav@70: /** jaroslav@70: * Constructs an AssertionError with no detail message. jaroslav@70: */ jaroslav@70: public AssertionError() { jaroslav@70: } jaroslav@70: jaroslav@70: /** jaroslav@70: * This internal constructor does no processing on its string argument, jaroslav@70: * even if it is a null reference. The public constructors will jaroslav@70: * never call this constructor with a null argument. jaroslav@70: */ jaroslav@70: private AssertionError(String detailMessage) { jaroslav@70: super(detailMessage); jaroslav@70: } jaroslav@70: jaroslav@70: /** jaroslav@70: * Constructs an AssertionError with its detail message derived jaroslav@70: * from the specified object, which is converted to a string as jaroslav@70: * defined in section 15.18.1.1 of jaroslav@70: * The Java™ Language Specification. jaroslav@70: *

jaroslav@70: * If the specified object is an instance of {@code Throwable}, it jaroslav@70: * becomes the cause of the newly constructed assertion error. jaroslav@70: * jaroslav@70: * @param detailMessage value to be used in constructing detail message jaroslav@70: * @see Throwable#getCause() jaroslav@70: */ jaroslav@70: public AssertionError(Object detailMessage) { jaroslav@70: this("" + detailMessage); jaroslav@70: if (detailMessage instanceof Throwable) jaroslav@70: initCause((Throwable) detailMessage); jaroslav@70: } jaroslav@70: jaroslav@70: /** jaroslav@70: * Constructs an AssertionError with its detail message derived jaroslav@70: * from the specified boolean, which is converted to jaroslav@70: * a string as defined in section 15.18.1.1 of jaroslav@70: * The Java™ Language Specification. jaroslav@70: * jaroslav@70: * @param detailMessage value to be used in constructing detail message jaroslav@70: */ jaroslav@70: public AssertionError(boolean detailMessage) { jaroslav@70: this("" + detailMessage); jaroslav@70: } jaroslav@70: jaroslav@70: /** jaroslav@70: * Constructs an AssertionError with its detail message derived jaroslav@70: * from the specified char, which is converted to a jaroslav@70: * string as defined in section 15.18.1.1 of jaroslav@70: * The Java™ Language Specification. jaroslav@70: * jaroslav@70: * @param detailMessage value to be used in constructing detail message jaroslav@70: */ jaroslav@70: public AssertionError(char detailMessage) { jaroslav@70: this("" + detailMessage); jaroslav@70: } jaroslav@70: jaroslav@70: /** jaroslav@70: * Constructs an AssertionError with its detail message derived jaroslav@70: * from the specified int, which is converted to a jaroslav@70: * string as defined in section 15.18.1.1 of jaroslav@70: * The Java™ Language Specification. jaroslav@70: * jaroslav@70: * @param detailMessage value to be used in constructing detail message jaroslav@70: */ jaroslav@70: public AssertionError(int detailMessage) { jaroslav@70: this("" + detailMessage); jaroslav@70: } jaroslav@70: jaroslav@70: /** jaroslav@70: * Constructs an AssertionError with its detail message derived jaroslav@70: * from the specified long, which is converted to a jaroslav@70: * string as defined in section 15.18.1.1 of jaroslav@70: * The Java™ Language Specification. jaroslav@70: * jaroslav@70: * @param detailMessage value to be used in constructing detail message jaroslav@70: */ jaroslav@70: public AssertionError(long detailMessage) { jaroslav@70: this("" + detailMessage); jaroslav@70: } jaroslav@70: jaroslav@70: /** jaroslav@70: * Constructs an AssertionError with its detail message derived jaroslav@70: * from the specified float, which is converted to a jaroslav@70: * string as defined in section 15.18.1.1 of jaroslav@70: * The Java™ Language Specification. jaroslav@70: * jaroslav@70: * @param detailMessage value to be used in constructing detail message jaroslav@70: */ jaroslav@70: public AssertionError(float detailMessage) { jaroslav@70: this("" + detailMessage); jaroslav@70: } jaroslav@70: jaroslav@70: /** jaroslav@70: * Constructs an AssertionError with its detail message derived jaroslav@70: * from the specified double, which is converted to a jaroslav@70: * string as defined in section 15.18.1.1 of jaroslav@70: * The Java™ Language Specification. jaroslav@70: * jaroslav@70: * @param detailMessage value to be used in constructing detail message jaroslav@70: */ jaroslav@70: public AssertionError(double detailMessage) { jaroslav@70: this("" + detailMessage); jaroslav@70: } jaroslav@70: jaroslav@70: /** jaroslav@70: * Constructs a new {@code AssertionError} with the specified jaroslav@70: * detail message and cause. jaroslav@70: * jaroslav@70: *

Note that the detail message associated with jaroslav@70: * {@code cause} is not automatically incorporated in jaroslav@70: * this error's detail message. jaroslav@70: * jaroslav@70: * @param message the detail message, may be {@code null} jaroslav@70: * @param cause the cause, may be {@code null} jaroslav@70: * jaroslav@70: * @since 1.7 jaroslav@70: */ jaroslav@70: public AssertionError(String message, Throwable cause) { jaroslav@70: super(message, cause); jaroslav@70: } jaroslav@70: }