public final class Throwables
extends java.lang.Object
Throwable.
NOTE: proxy for the Guava implementation of Throwables.
| Modifier and Type | Method and Description |
|---|---|
static java.lang.RuntimeException |
propagate(java.lang.Throwable 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(java.lang.Throwable throwable)
Propagates
throwable exactly as-is, if and only if it is an instance of
RuntimeException or Error. |
static <X extends java.lang.Throwable> |
propagateIfPossible(java.lang.Throwable throwable,
java.lang.Class<X> declaredType)
Propagates
throwable exactly as-is, if and only if it is an instance of
RuntimeException, Error, or declaredType. |
public static java.lang.RuntimeException propagate(java.lang.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 propagatepublic static void propagateIfPossible(java.lang.Throwable throwable)
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 java.lang.Throwable> void propagateIfPossible(java.lang.Throwable throwable,
java.lang.Class<X> declaredType)
throws X extends java.lang.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 methodX extends java.lang.ThrowableCopyright © 2011-2018 Google. All Rights Reserved.