Class ThrowingEx


  • public final class ThrowingEx
    extends java.lang.Object
    Basic functional interfaces which throw exception, along with static helper methods for calling them.

    Contains most of the functionality of Durian's Throwing and Errors classes, but stripped down and renamed to avoid any confusion.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.RuntimeException asRuntime​(java.lang.Exception e)
      Casts or wraps the given exception to be a RuntimeException.
      static <T> T get​(ThrowingEx.Supplier<T> supplier)
      Gets the given value, rethrowing any exceptions as runtime exceptions.
      static void run​(ThrowingEx.Runnable runnable)
      Runs the given runnable, rethrowing any exceptions as runtime exceptions.
      static java.lang.RuntimeException unwrapCause​(java.lang.Throwable e)
      Utility method for rethrowing an exception's cause with as few wrappers as possible.
      static <T,​R>
      java.util.function.Function<T,​R>
      wrap​(ThrowingEx.Function<T,​R> function)
      Wraps the given ThrowingEx.Function as a standard Function, rethrowing any exceptions as runtime exceptions.
      • Methods inherited from class java.lang.Object

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

      • run

        public static void run​(ThrowingEx.Runnable runnable)
        Runs the given runnable, rethrowing any exceptions as runtime exceptions.
      • get

        public static <T> T get​(ThrowingEx.Supplier<T> supplier)
        Gets the given value, rethrowing any exceptions as runtime exceptions.
      • wrap

        public static <T,​R> java.util.function.Function<T,​R> wrap​(ThrowingEx.Function<T,​R> function)
        Wraps the given ThrowingEx.Function as a standard Function, rethrowing any exceptions as runtime exceptions.
      • asRuntime

        public static java.lang.RuntimeException asRuntime​(java.lang.Exception e)
        Casts or wraps the given exception to be a RuntimeException.

        If the input exception is a RuntimeException, it is simply cast and returned. Otherwise, it wrapped in a ThrowingEx.WrappedAsRuntimeException and returned.

      • unwrapCause

        public static java.lang.RuntimeException unwrapCause​(java.lang.Throwable e)
        Utility method for rethrowing an exception's cause with as few wrappers as possible.
        
         try {
             doSomething();
         } catch (Throwable e) {
             throw unwrapCause(e);
         }