Class Throwables


  • @Deprecated
    public final class Throwables
    extends java.lang.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
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  Throwables.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>
      R
      propagate​(java.lang.Throwable throwable, java.lang.Class<R> runtimeType)
      Deprecated.
      since 2.4, no need in Java7 with closeWithResources and multi-catch
      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-catch
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Throwables

        public Throwables()
        Deprecated.
    • 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-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 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-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:
        propagate(Throwable, Function)