1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package java.lang; 19 20/** 21 * Thrown when an assertion has failed. 22 * 23 * @since 1.4 24 */ 25public class AssertionError extends Error { 26 27 private static final long serialVersionUID = -5013299493970297370L; 28 29 /** 30 * Constructs a new {@code AssertionError} with no message. 31 */ 32 public AssertionError() { 33 } 34 35 /** 36 * Constructs a new {@code AssertionError} with the given detail message and cause. 37 * @since 1.7 38 * @hide 1.7 39 */ 40 public AssertionError(String detailMessage, Throwable cause) { 41 super(detailMessage, cause); 42 } 43 44 /** 45 * Constructs a new {@code AssertionError} with a message based on calling 46 * {@link String#valueOf(Object)} with the specified object. If the object 47 * is an instance of {@link Throwable}, then it also becomes the cause of 48 * this error. 49 * 50 * @param detailMessage 51 * the object to be converted into the detail message and 52 * optionally the cause. 53 */ 54 public AssertionError(Object detailMessage) { 55 super(String.valueOf(detailMessage)); 56 if (detailMessage instanceof Throwable) { 57 initCause((Throwable) detailMessage); 58 } 59 } 60 61 /** 62 * Constructs a new {@code AssertionError} with a message based on calling 63 * {@link String#valueOf(boolean)} with the specified boolean value. 64 * 65 * @param detailMessage 66 * the value to be converted into the message. 67 */ 68 public AssertionError(boolean detailMessage) { 69 this(String.valueOf(detailMessage)); 70 } 71 72 /** 73 * Constructs a new {@code AssertionError} with a message based on calling 74 * {@link String#valueOf(char)} with the specified character value. 75 * 76 * @param detailMessage 77 * the value to be converted into the message. 78 */ 79 public AssertionError(char detailMessage) { 80 this(String.valueOf(detailMessage)); 81 } 82 83 /** 84 * Constructs a new {@code AssertionError} with a message based on calling 85 * {@link String#valueOf(int)} with the specified integer value. 86 * 87 * @param detailMessage 88 * the value to be converted into the message. 89 */ 90 public AssertionError(int detailMessage) { 91 this(Integer.toString(detailMessage)); 92 } 93 94 /** 95 * Constructs a new {@code AssertionError} with a message based on calling 96 * {@link String#valueOf(long)} with the specified long value. 97 * 98 * @param detailMessage 99 * the value to be converted into the message. 100 */ 101 public AssertionError(long detailMessage) { 102 this(Long.toString(detailMessage)); 103 } 104 105 /** 106 * Constructs a new {@code AssertionError} with a message based on calling 107 * {@link String#valueOf(float)} with the specified float value. 108 * 109 * @param detailMessage 110 * the value to be converted into the message. 111 */ 112 public AssertionError(float detailMessage) { 113 this(Float.toString(detailMessage)); 114 } 115 116 /** 117 * Constructs a new {@code AssertionError} with a message based on calling 118 * {@link String#valueOf(double)} with the specified double value. 119 * 120 * @param detailMessage 121 * the value to be converted into the message. 122 */ 123 public AssertionError(double detailMessage) { 124 this(Double.toString(detailMessage)); 125 } 126} 127