001 /*
002 * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package java.lang;
027
028 /**
029 * Thrown to indicate that an assertion has failed.
030 *
031 * <p>The seven one-argument public constructors provided by this
032 * class ensure that the assertion error returned by the invocation:
033 * <pre>
034 * new AssertionError(<i>expression</i>)
035 * </pre>
036 * has as its detail message the <i>string conversion</i> of
037 * <i>expression</i> (as defined in <a
038 * href="http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html">
039 * <i>The Java Language Specification, Second Edition</i></a>,
040 * <a href="http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#40220">
041 * Section 15.18.1.1</a>), regardless of the type of <i>expression</i>.
042 *
043 * @version 1.15, 05/05/07
044 * @since 1.4
045 */
046 public class AssertionError extends Error {
047 /**
048 * Constructs an AssertionError with no detail message.
049 */
050 public AssertionError() {
051 }
052
053 /**
054 * This internal constructor does no processing on its string argument,
055 * even if it is a null reference. The public constructors will
056 * never call this constructor with a null argument.
057 */
058 private AssertionError(String detailMessage) {
059 super (detailMessage);
060 }
061
062 /**
063 * Constructs an AssertionError with its detail message derived
064 * from the specified object, which is converted to a string as
065 * defined in <i>The Java Language Specification, Second
066 * Edition</i>, Section 15.18.1.1.
067 *<p>
068 * If the specified object is an instance of <tt>Throwable</tt>, it
069 * becomes the <i>cause</i> of the newly constructed assertion error.
070 *
071 * @param detailMessage value to be used in constructing detail message
072 * @see Throwable#getCause()
073 */
074 public AssertionError(Object detailMessage) {
075 this ("" + detailMessage);
076 if (detailMessage instanceof Throwable)
077 initCause((Throwable) detailMessage);
078 }
079
080 /**
081 * Constructs an AssertionError with its detail message derived
082 * from the specified <code>boolean</code>, which is converted to
083 * a string as defined in <i>The Java Language Specification,
084 * Second Edition</i>, Section 15.18.1.1.
085 *
086 * @param detailMessage value to be used in constructing detail message
087 */
088 public AssertionError(boolean detailMessage) {
089 this ("" + detailMessage);
090 }
091
092 /**
093 * Constructs an AssertionError with its detail message derived
094 * from the specified <code>char</code>, which is converted to a
095 * string as defined in <i>The Java Language Specification, Second
096 * Edition</i>, Section 15.18.1.1.
097 *
098 * @param detailMessage value to be used in constructing detail message
099 */
100 public AssertionError(char detailMessage) {
101 this ("" + detailMessage);
102 }
103
104 /**
105 * Constructs an AssertionError with its detail message derived
106 * from the specified <code>int</code>, which is converted to a
107 * string as defined in <i>The Java Language Specification, Second
108 * Edition</i>, Section 15.18.1.1.
109 *
110 * @param detailMessage value to be used in constructing detail message
111 */
112 public AssertionError(int detailMessage) {
113 this ("" + detailMessage);
114 }
115
116 /**
117 * Constructs an AssertionError with its detail message derived
118 * from the specified <code>long</code>, which is converted to a
119 * string as defined in <i>The Java Language Specification, Second
120 * Edition</i>, Section 15.18.1.1.
121 *
122 * @param detailMessage value to be used in constructing detail message
123 */
124 public AssertionError(long detailMessage) {
125 this ("" + detailMessage);
126 }
127
128 /**
129 * Constructs an AssertionError with its detail message derived
130 * from the specified <code>float</code>, which is converted to a
131 * string as defined in <i>The Java Language Specification, Second
132 * Edition</i>, Section 15.18.1.1.
133 *
134 * @param detailMessage value to be used in constructing detail message
135 */
136 public AssertionError(float detailMessage) {
137 this ("" + detailMessage);
138 }
139
140 /**
141 * Constructs an AssertionError with its detail message derived
142 * from the specified <code>double</code>, which is converted to a
143 * string as defined in <i>The Java Language Specification, Second
144 * Edition</i>, Section 15.18.1.1.
145 *
146 * @param detailMessage value to be used in constructing detail message
147 */
148 public AssertionError(double detailMessage) {
149 this ("" + detailMessage);
150 }
151 }
|