@Deprecated public final class Throwables extends Object
Throwable
not provided by Guava.| Constructor and Description |
|---|
Throwables()
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
static <R extends RuntimeException> |
propagate(Throwable throwable,
Class<R> runtimeType)
Deprecated.
since 2.4, no need in Java7 with closeWithResources and
multi-catch
|
static <R extends RuntimeException> |
propagate(Throwable throwable,
Function<Throwable,R> function)
Deprecated.
since 2.4, no need in Java7 with closeWithResources and
multi-catch
|
@Deprecated public static <R extends RuntimeException> R propagate(Throwable throwable, Function<Throwable,R> function)
throwable as-is if it is an instance of
RuntimeException or Error, or else as a
last resort, wraps it in a RuntimeException provided by the
function and 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, new Function<MyRuntimeException>() {
public MyRuntimeException apply(Throwable t) {
return new MyRuntimeException(t);
}
});
}
}
R - exception typethrowable - the Throwable to propagatefunction - the function to transform the throwable into a runtime
exception@Deprecated public static <R extends RuntimeException> R propagate(Throwable throwable, Class<R> runtimeType)
throwable as-is if it is an instance of
RuntimeException or Error, or else as a
last resort, wraps it in the RuntimeException specified by the
runtimeType parameter provided and 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.
The runtime type passed as a parameter must be a runtime exception with a
constructor taking a single Throwable as an argument accessible via
reflection. If this is not the case an appropriate exception (
NoSuchMethodException, InstantiationException,
IllegalAccessException, InvocationTargetException) will be
thrown wrapped in a simple RuntimeException. If you can't make your
exception match those criteria, you might want to look at using
propagate(Throwable, Function).
Example usage:
T doSomething() {
try {
return someMethodThatCouldThrowAnything();
} catch (IKnowWhatToDoWithThisException e) {
return handle(e);
} catch (Throwable t) {
throw Throwables.propagate(t, MyRuntimeException.class);
}
}
R - exception typethrowable - the Throwable to propagateruntimeType - the type of exception to use.propagate(Throwable, Function)Copyright © 2017 Atlassian. All rights reserved.