1. /*
  2. * @(#)AssertionError.java 1.7 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.lang;
  8. /**
  9. * Thrown to indicate that an assertion has failed.
  10. *
  11. * <p>The seven one-argument public constructors provided by this
  12. * class ensure that the assertion error returned by the invocation:
  13. * <pre>
  14. * new AssertionError(<i>expression</i>)
  15. * </pre>
  16. * has as its detail message the <i>string conversion</i> of
  17. * <i>expression</i> (as defined in <a
  18. * href="http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html">
  19. * <i>The Java Language Specification, Second Edition</i></a>,
  20. * <a href="http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#40220">
  21. * Section 15.18.1.1</a>), regardless of the type of <i>expression</i>.
  22. *
  23. * @version 1.7, 12/19/03
  24. * @since JDK1.4
  25. */
  26. public class AssertionError extends Error {
  27. /**
  28. * Constructs an AssertionError with no detail message.
  29. */
  30. public AssertionError() {
  31. }
  32. /**
  33. * This internal constructor does no processing on its string argument,
  34. * even if it is a null reference. The public constructors will
  35. * never call this constructor with a null argument.
  36. */
  37. private AssertionError(String detailMessage) {
  38. super(detailMessage);
  39. }
  40. /**
  41. * Constructs an AssertionError with its detail message derived
  42. * from the specified object, which is converted to a string as
  43. * defined in <i>The Java Language Specification, Second
  44. * Edition</i>, Section 15.18.1.1.
  45. *<p>
  46. * If the specified object is an instance of <tt>Throwable</tt>, it
  47. * becomes the <i>cause</i> of the newly constructed assertion error.
  48. *
  49. * @param detailMessage value to be used in constructing detail message
  50. * @see Throwable#getCause()
  51. */
  52. public AssertionError(Object detailMessage) {
  53. this("" + detailMessage);
  54. if (detailMessage instanceof Throwable)
  55. initCause((Throwable) detailMessage);
  56. }
  57. /**
  58. * Constructs an AssertionError with its detail message derived
  59. * from the specified <code>boolean</code>, which is converted to
  60. * a string as defined in <i>The Java Language Specification,
  61. * Second Edition</i>, Section 15.18.1.1.
  62. *
  63. * @param detailMessage value to be used in constructing detail message
  64. */
  65. public AssertionError(boolean detailMessage) {
  66. this("" + detailMessage);
  67. }
  68. /**
  69. * Constructs an AssertionError with its detail message derived
  70. * from the specified <code>char</code>, which is converted to a
  71. * string as defined in <i>The Java Language Specification, Second
  72. * Edition</i>, Section 15.18.1.1.
  73. *
  74. * @param detailMessage value to be used in constructing detail message
  75. */
  76. public AssertionError(char detailMessage) {
  77. this("" + detailMessage);
  78. }
  79. /**
  80. * Constructs an AssertionError with its detail message derived
  81. * from the specified <code>int</code>, which is converted to a
  82. * string as defined in <i>The Java Language Specification, Second
  83. * Edition</i>, Section 15.18.1.1.
  84. *
  85. * @param detailMessage value to be used in constructing detail message
  86. */
  87. public AssertionError(int detailMessage) {
  88. this("" + detailMessage);
  89. }
  90. /**
  91. * Constructs an AssertionError with its detail message derived
  92. * from the specified <code>long</code>, which is converted to a
  93. * string as defined in <i>The Java Language Specification, Second
  94. * Edition</i>, Section 15.18.1.1.
  95. *
  96. * @param detailMessage value to be used in constructing detail message
  97. */
  98. public AssertionError(long detailMessage) {
  99. this("" + detailMessage);
  100. }
  101. /**
  102. * Constructs an AssertionError with its detail message derived
  103. * from the specified <code>float</code>, which is converted to a
  104. * string as defined in <i>The Java Language Specification, Second
  105. * Edition</i>, Section 15.18.1.1.
  106. *
  107. * @param detailMessage value to be used in constructing detail message
  108. */
  109. public AssertionError(float detailMessage) {
  110. this("" + detailMessage);
  111. }
  112. /**
  113. * Constructs an AssertionError with its detail message derived
  114. * from the specified <code>double</code>, which is converted to a
  115. * string as defined in <i>The Java Language Specification, Second
  116. * Edition</i>, Section 15.18.1.1.
  117. *
  118. * @param detailMessage value to be used in constructing detail message
  119. */
  120. public AssertionError(double detailMessage) {
  121. this("" + detailMessage);
  122. }
  123. }