| 1 | /* |
| 2 | * JTiger Unit Testing Framework for J2SE 1.5 |
| 3 | * Copyright (C) 2005 Tony Morris |
| 4 | * |
| 5 | * This software is licenced under the |
| 6 | * Common Public Licence version 1.0 |
| 7 | * http://www.opensource.org/licenses/cpl1.0.php |
| 8 | * |
| 9 | * You received a copy of this licence with this software. |
| 10 | */ |
| 11 | package org.jtiger.assertion; |
| 12 | |
| 13 | /** |
| 14 | * An exception that may be thrown to indicate that an assertion was not met. |
| 15 | * |
| 16 | * @author %javadoc.author.tag% |
| 17 | * @version %version%<br/> |
| 18 | * <i>Build Number %build.number%</i><br/> |
| 19 | * <i>Build Time %build.time% CET (GMT + 1)</i> |
| 20 | */ |
| 21 | public final class AssertionException extends RuntimeException |
| 22 | { |
| 23 | private final String message; |
| 24 | |
| 25 | /** |
| 26 | * Create a default <tt>AssertionException</tt>. |
| 27 | */ |
| 28 | public AssertionException() |
| 29 | { |
| 30 | message = super.getMessage(); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Create a <tt>AssertionException</tt> with the given message. |
| 35 | * |
| 36 | * @param message The message of the <tt>AssertionException</tt>. |
| 37 | */ |
| 38 | public AssertionException(final Object... message) |
| 39 | { |
| 40 | final StringBuilder sb = new StringBuilder(); |
| 41 | |
| 42 | for(Object o : message) |
| 43 | { |
| 44 | sb.append(o); |
| 45 | } |
| 46 | |
| 47 | this.message = sb.toString(); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Create a <tt>AssertionException</tt> with the given cause. |
| 52 | * |
| 53 | * @param cause The cause of the <tt>AssertionException</tt>. |
| 54 | */ |
| 55 | public AssertionException(final Throwable cause) |
| 56 | { |
| 57 | super(cause); |
| 58 | message = super.getMessage(); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Create a <tt>AssertionException</tt> with the given message and cause. |
| 63 | * |
| 64 | * @param cause The cause of the <tt>AssertionException</tt>. |
| 65 | * @param message The message of the <tt>AssertionException</tt>. |
| 66 | */ |
| 67 | public AssertionException(final Throwable cause, final Object... message) |
| 68 | { |
| 69 | super(cause); |
| 70 | |
| 71 | final StringBuilder sb = new StringBuilder(); |
| 72 | |
| 73 | for(Object o : message) |
| 74 | { |
| 75 | sb.append(o); |
| 76 | } |
| 77 | |
| 78 | this.message = sb.toString(); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Returns the message for this exception which may be concatenated by passing multiple arguments to constructors. |
| 83 | * |
| 84 | * @return The message for this exception which may be concatenated by passing multiple arguments to constructors. |
| 85 | */ |
| 86 | public String getMessage() |
| 87 | { |
| 88 | return message; |
| 89 | } |
| 90 | } |