Class Throwables
- java.lang.Object
-
- io.atlassian.fugue.deprecated.Throwables
-
@Deprecated public final class Throwables extends java.lang.ObjectDeprecated.since 2.4, no need in Java7 with closeWithResources and multi-catchStatic utility methods pertaining to instances ofThrowablenot provided by Guava.- Since:
- 1.2
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classThrowables.ExceptionFunction<E extends java.lang.Exception>Deprecated.
-
Constructor Summary
Constructors Constructor Description Throwables()Deprecated.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <R extends java.lang.RuntimeException>
Rpropagate(java.lang.Throwable throwable, java.lang.Class<R> runtimeType)Deprecated.since 2.4, no need in Java7 with closeWithResources and multi-catchstatic <R extends java.lang.RuntimeException>
Rpropagate(java.lang.Throwable throwable, java.util.function.Function<java.lang.Throwable,R> function)Deprecated.since 2.4, no need in Java7 with closeWithResources and multi-catch
-
-
-
Method Detail
-
propagate
@Deprecated public static <R extends java.lang.RuntimeException> R propagate(java.lang.Throwable throwable, java.util.function.Function<java.lang.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 java.lang.RuntimeException> R propagate(java.lang.Throwable throwable, java.lang.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:
propagate(Throwable, Function)
-
-