Home | History | Annotate | Download | only in lang
      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 
     18 package java.lang;
     19 
     20 /**
     21  * Thrown when an assertion has failed.
     22  *
     23  * @since 1.4
     24  */
     25 public 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         super();
     34     }
     35 
     36     /**
     37      * Constructs a new {@code AssertionError} with a message based on calling
     38      * {@link String#valueOf(Object)} with the specified object. If the object
     39      * is an instance of {@link Throwable}, then it also becomes the cause of
     40      * this error.
     41      *
     42      * @param detailMessage
     43      *            the object to be converted into the detail message and
     44      *            optionally the cause.
     45      */
     46     public AssertionError(Object detailMessage) {
     47         super(String.valueOf(detailMessage),
     48                 (detailMessage instanceof Throwable ? (Throwable) detailMessage
     49                         : null));
     50     }
     51 
     52     /**
     53      * Constructs a new {@code AssertionError} with a message based on calling
     54      * {@link String#valueOf(boolean)} with the specified boolean value.
     55      *
     56      * @param detailMessage
     57      *            the value to be converted into the message.
     58      */
     59     public AssertionError(boolean detailMessage) {
     60         this(String.valueOf(detailMessage));
     61     }
     62 
     63     /**
     64      * Constructs a new {@code AssertionError} with a message based on calling
     65      * {@link String#valueOf(char)} with the specified character value.
     66      *
     67      * @param detailMessage
     68      *            the value to be converted into the message.
     69      */
     70     public AssertionError(char detailMessage) {
     71         this(String.valueOf(detailMessage));
     72     }
     73 
     74     /**
     75      * Constructs a new {@code AssertionError} with a message based on calling
     76      * {@link String#valueOf(int)} with the specified integer value.
     77      *
     78      * @param detailMessage
     79      *            the value to be converted into the message.
     80      */
     81     public AssertionError(int detailMessage) {
     82         this(Integer.toString(detailMessage));
     83     }
     84 
     85     /**
     86      * Constructs a new {@code AssertionError} with a message based on calling
     87      * {@link String#valueOf(long)} with the specified long value.
     88      *
     89      * @param detailMessage
     90      *            the value to be converted into the message.
     91      */
     92     public AssertionError(long detailMessage) {
     93         this(Long.toString(detailMessage));
     94     }
     95 
     96     /**
     97      * Constructs a new {@code AssertionError} with a message based on calling
     98      * {@link String#valueOf(float)} with the specified float value.
     99      *
    100      * @param detailMessage
    101      *            the value to be converted into the message.
    102      */
    103     public AssertionError(float detailMessage) {
    104         this(Float.toString(detailMessage));
    105     }
    106 
    107     /**
    108      * Constructs a new {@code AssertionError} with a message based on calling
    109      * {@link String#valueOf(double)} with the specified double value.
    110      *
    111      * @param detailMessage
    112      *            the value to be converted into the message.
    113      */
    114     public AssertionError(double detailMessage) {
    115         this(Double.toString(detailMessage));
    116     }
    117 }
    118