Package com.google.api.client.util
Class Throwables
- java.lang.Object
-
- com.google.api.client.util.Throwables
-
public final class Throwables extends java.lang.ObjectStatic utility methods pertaining to instances ofThrowable.NOTE: proxy for the Guava implementation of
Throwables.- Since:
- 1.14
-
-
Constructor Summary
Constructors Modifier Constructor Description privateThrowables()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.RuntimeExceptionpropagate(java.lang.Throwable throwable)Propagatesthrowableas-is if it is an instance ofRuntimeExceptionorError, or else as a last resort, wraps it in aRuntimeExceptionthen propagates.static voidpropagateIfPossible(java.lang.Throwable throwable)Propagatesthrowableexactly as-is, if and only if it is an instance ofRuntimeExceptionorError.static <X extends java.lang.Throwable>
voidpropagateIfPossible(java.lang.Throwable throwable, java.lang.Class<X> declaredType)Propagatesthrowableexactly as-is, if and only if it is an instance ofRuntimeException,Error, ordeclaredType.
-
-
-
Method Detail
-
propagate
public static java.lang.RuntimeException propagate(java.lang.Throwable throwable)
Propagatesthrowableas-is if it is an instance ofRuntimeExceptionorError, or else as a last resort, wraps it in aRuntimeExceptionthen 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); } }- Parameters:
throwable- the Throwable to propagate- Returns:
- nothing will ever be returned; this return type is only for your convenience, as illustrated in the example above
-
propagateIfPossible
public static void propagateIfPossible(java.lang.Throwable throwable)
Propagatesthrowableexactly as-is, if and only if it is an instance ofRuntimeExceptionorError. Example usage:try { someMethodThatCouldThrowAnything(); } catch (IKnowWhatToDoWithThisException e) { handle(e); } catch (Throwable t) { Throwables.propagateIfPossible(t); throw new RuntimeException("unexpected", t); }- Parameters:
throwable- throwable (may benull)
-
propagateIfPossible
public static <X extends java.lang.Throwable> void propagateIfPossible(java.lang.Throwable throwable, java.lang.Class<X> declaredType) throws X extends java.lang.ThrowablePropagatesthrowableexactly as-is, if and only if it is an instance ofRuntimeException,Error, ordeclaredType. Example usage:try { someMethodThatCouldThrowAnything(); } catch (IKnowWhatToDoWithThisException e) { handle(e); } catch (Throwable t) { Throwables.propagateIfPossible(t, OtherException.class); throw new RuntimeException("unexpected", t); }- Parameters:
throwable- throwable (may benull)declaredType- the single checked exception type declared by the calling method- Throws:
X extends java.lang.Throwable
-
-