Class Throwables

java.lang.Object
io.atlassian.fugue.deprecated.Throwables

@Deprecated public final class Throwables extends Object
Deprecated.
since 2.4, no need in Java7 with closeWithResources and multi-catch
Static utility methods pertaining to instances of Throwable not provided by Guava.
Since:
1.2
  • 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-catch
      Propagates 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);
             }
           });
         }
       }
       
      Type Parameters:
      R - exception type
      Parameters:
      throwable - the Throwable to propagate
      function - 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-catch
      Propagates 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);
         }
       }
       
      Type Parameters:
      R - exception type
      Parameters:
      throwable - the Throwable to propagate
      runtimeType - 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: