| 1 | package com.github.dakusui.actionunit.exceptions; | |
| 2 | ||
| 3 | /** | |
| 4 | * Encapsulate a general Action error or warning. | |
| 5 | */ | |
| 6 | public class ActionException extends RuntimeException { | |
| 7 | /** | |
| 8 | * Creates a new {@code ActionException} with a given message. | |
| 9 | * | |
| 10 | * @param message The detail message. | |
| 11 | */ | |
| 12 | public ActionException(String message) { | |
| 13 | this(message, null); | |
| 14 | } | |
| 15 | ||
| 16 | /** | |
| 17 | * Creates a new {@code ActionException} from an existing exception. | |
| 18 | * The existing exception will be embedded in the new one, | |
| 19 | * | |
| 20 | * @param t The exception to be wrapped in a {@code ActionException}. | |
| 21 | */ | |
| 22 | public ActionException(Throwable t) { | |
| 23 | this(null, t); | |
| 24 | } | |
| 25 | ||
| 26 | /** | |
| 27 | * Creates a new {@code ActionException} from an existing exception. | |
| 28 | * The existing exception will be embedded in the new one, but the new exception will have its own | |
| 29 | * message. | |
| 30 | * | |
| 31 | * @param message The detail message. | |
| 32 | * @param t The exception to be wrapped in a {@code ActionException}. | |
| 33 | */ | |
| 34 | public ActionException(String message, Throwable t) { | |
| 35 | super(message, t); | |
| 36 | } | |
| 37 | ||
| 38 | ||
| 39 | /** | |
| 40 | * Wraps a given exception if necessary. | |
| 41 | * | |
| 42 | * Note that this method throws an exception itself or that wraps the given throwable, not returns. | |
| 43 | * Therefore, this method never finishes. | |
| 44 | * | |
| 45 | * You can construct a throw statement using this method. | |
| 46 | * That is, you can construct a statement: `throw wrap(anException);`, which | |
| 47 | * doesn't confuse static code analysis. | |
| 48 | * | |
| 49 | * @param t An exception to be rethrown. | |
| 50 | * @return Will never be returned, but thrown. | |
| 51 | * @param <T> Type of exception to be thrown. | |
| 52 | */ | |
| 53 | public static <T extends ActionException> T wrap(Throwable t) { | |
| 54 |
1
1. wrap : negated conditional → KILLED |
if (t == null) { |
| 55 | throw new ActionException(t); | |
| 56 | } | |
| 57 |
1
1. wrap : negated conditional → KILLED |
if (t instanceof Error) { |
| 58 | throw (Error) t; | |
| 59 | } | |
| 60 |
1
1. wrap : negated conditional → KILLED |
if (t instanceof RuntimeException) { |
| 61 | throw (RuntimeException) t; | |
| 62 | } | |
| 63 | throw new ActionException(t.getMessage(), t); | |
| 64 | } | |
| 65 | } | |
Mutations | ||
| 54 |
1.1 |
|
| 57 |
1.1 |
|
| 60 |
1.1 |