public class MoreThrowables extends Object
| Modifier and Type | Method and Description |
|---|---|
static Throwable |
getInitialCause(Throwable throwable)
If throwable has a non-empty cause, returns throwable at the bottom of the stack.
|
static String |
getThrowableOrigin(Throwable throwable)
Returns string representing class, method, filename and line number that throwable was thrown
from
|
static void |
propagateIfInterrupt(Throwable thrown)
Propagates an
InterruptedException masquerading as another Throwable. |
static <X extends Throwable> |
throwIfAnyCauseInstanceOf(Throwable throwable,
Class<X> declaredType)
Traverse exception chain by recursively calling
getCause() and throws it if there is
any exception found which is an instance of declaredType. |
static <X extends Throwable> |
throwIfInitialCauseInstanceOf(Throwable throwable,
Class<X> declaredType)
Traverse exception chain by recursively calling
getCause() and throws it if initial
exception (the one at the bottom of the stack) is an instance of declaredType. |
public static void propagateIfInterrupt(Throwable thrown) throws InterruptedException
InterruptedException masquerading as another Throwable.InterruptedExceptionpublic static Throwable getInitialCause(Throwable throwable)
public static String getThrowableOrigin(Throwable throwable)
public static <X extends Throwable> void throwIfAnyCauseInstanceOf(Throwable throwable, Class<X> declaredType) throws X extends Throwable
getCause() and throws it if there is
any exception found which is an instance of declaredType. Example usage:
try {
future.get()
} catch (ExecutionException) {
MoreThrowables.throwIfAnyCauseInstanceOf(t, BarException.class);
}X extends Throwablepublic static <X extends Throwable> void throwIfInitialCauseInstanceOf(Throwable throwable, Class<X> declaredType) throws X extends Throwable
getCause() and throws it if initial
exception (the one at the bottom of the stack) is an instance of declaredType.
Example usage:
try {
future.get()
} catch (ExecutionException) {
MoreThrowables.throwIfInitialCauseInstanceOf(t, BarException.class);
}X extends Throwable