| Modifier and Type | Method and Description |
|---|---|
static RuntimeException |
propagate(Throwable
Propagates
throwable as-is if it is an instance of
RuntimeException or
Error, or else as a last resort, wraps it in a
RuntimeException then propagates.
|
static void |
propagateIfPossible(Throwable
|
static <X extends Throwable |
propagateIfPossible(Throwable
Propagates
throwable exactly as-is, if and only if it is an instance of
RuntimeException,
Error, or
declaredType.
|
public static RuntimeExceptionpropagate(Throwable throwable)
throwable as-is if it is an instance of
RuntimeException or
Error, or else as a last resort, wraps it in a
RuntimeException then propagates.
This method always throws an exception. The RuntimeException return type is only for client code to make Java type system happy in case a return value is required by the enclosing method. Example usage:
T doSomething() {
try {
return someMethodThatCouldThrowAnything();
} catch (IKnowWhatToDoWithThisException e) {
return handle(e);
} catch (Throwable t) {
throw Throwables.propagate(t);
}
}
throwable - the Throwable to propagate
public static void propagateIfPossible(Throwablethrowable)
throwable exactly as-is, if and only if it is an instance of
RuntimeException or
Error. Example usage:
try {
someMethodThatCouldThrowAnything();
} catch (IKnowWhatToDoWithThisException e) {
handle(e);
} catch (Throwable t) {
Throwables.propagateIfPossible(t);
throw new RuntimeException("unexpected", t);
}
throwable - throwable (may be
null)
public static <X extends Throwable> void propagateIfPossible(Throwable throwable, Class <X> declaredType) throws X extends Throwable
throwable exactly as-is, if and only if it is an instance of
RuntimeException,
Error, or
declaredType. Example usage:
try {
someMethodThatCouldThrowAnything();
} catch (IKnowWhatToDoWithThisException e) {
handle(e);
} catch (Throwable t) {
Throwables.propagateIfPossible(t, OtherException.class);
throw new RuntimeException("unexpected", t);
}
throwable - throwable (may be
null)
declaredType - the single checked exception type declared by the calling method
X extends Throwable