Class Throwables
Throwable
not provided by Guava.- Since:
- 1.2
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classThrowables.ExceptionFunction<E extends Exception>Deprecated. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <R extends RuntimeException>
RDeprecated.since 2.4, no need in Java7 with closeWithResources and multi-catchstatic <R extends RuntimeException>
RDeprecated.since 2.4, no need in Java7 with closeWithResources and multi-catch
-
Constructor Details
-
Throwables
public Throwables()Deprecated.
-
-
Method Details
-
propagate
@Deprecated public static <R extends RuntimeException> R propagate(Throwable throwable, Function<Throwable, R> function) Deprecated.since 2.4, no need in Java7 with closeWithResources and multi-catchPropagatesthrowableas-is if it is an instance ofRuntimeExceptionorError, or else as a last resort, wraps it in aRuntimeExceptionprovided by the function and then propagates.This method always throws an exception. The
RuntimeExceptionreturn 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); } }); } }- Type Parameters:
R- exception type- Parameters:
throwable- the Throwable to propagatefunction- the function to transform the throwable into a runtime exception- Returns:
- nothing will ever be returned; this return type is only for your convenience, as illustrated in the example above
-
propagate
@Deprecated public static <R extends RuntimeException> R propagate(Throwable throwable, Class<R> runtimeType) Deprecated.since 2.4, no need in Java7 with closeWithResources and multi-catchPropagatesthrowableas-is if it is an instance ofRuntimeExceptionorError, or else as a last resort, wraps it in theRuntimeExceptionspecified by theruntimeTypeparameter provided and then propagates.This method always throws an exception. The
RuntimeExceptionreturn 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
Throwableas an argument accessible via reflection. If this is not the case an appropriate exception (NoSuchMethodException,InstantiationException,IllegalAccessException,InvocationTargetException) will be thrown wrapped in a simpleRuntimeException. If you can't make your exception match those criteria, you might want to look at usingpropagate(Throwable, Function).Example usage:
T doSomething() { try { return someMethodThatCouldThrowAnything(); } catch (IKnowWhatToDoWithThisException e) { return handle(e); } catch (Throwable t) { throw Throwables.propagate(t, MyRuntimeException.class); } }- Type Parameters:
R- exception type- Parameters:
throwable- the Throwable to propagateruntimeType- the type of exception to use.- Returns:
- nothing will ever be returned; this return type is only for your convenience, as illustrated in the example above
- See Also:
-