Class ExceptionUtils


  • public class ExceptionUtils
    extends java.lang.Object
    Utilities related to exception throwing and handling.
    • Method Detail

      • uncheckedConsumer

        public static <T> Consumer<T> uncheckedConsumer​(ExceptionUtils.ThrowingConsumer<T> wrap)
        Wrap consumer throwing exceptions to regular consumer.
        Type Parameters:
        T - type parameter
        Parameters:
        wrap - the consumer to wrap
        Returns:
        regular consumer
      • unchecked

        public static void unchecked​(ExceptionUtils.ThrowingRunnable runnable)
        Run given runnable rethrowing exceptions as RuntimeExceptions.
        Parameters:
        runnable - the runnable to run
      • uncheckedFactory

        public static <T> T uncheckedFactory​(ExceptionUtils.ThrowingFactory<T> factory)
        Run given factory and return result.
        Type Parameters:
        T - type parameter
        Parameters:
        factory - the factory that throws exceptions
        Returns:
        created instance of the factory
      • uncheckedFn

        public static <IN,​OUT> UnaryFunction<IN,​OUT> uncheckedFn​(ExceptionUtils.ThrowingUnaryFunction<IN,​OUT> fn)
        Wrap throwing unary function as regular one.
        Type Parameters:
        IN - input type parameter
        OUT - output type parameter
        Parameters:
        fn - the function to wrap
        Returns:
        regular unary function
      • ignoringInterrupted

        public static boolean ignoringInterrupted​(ExceptionUtils.ThrowingRunnable runnable)
        Run given runnable, swallow any potential InterruptedException and set current thread's interrupted flag (if exception caught).
        Parameters:
        runnable - runnable throwing InterruptedException
        Returns:
        true if InterruptedException was caught
      • isInterrupted

        public static boolean isInterrupted​(java.lang.Throwable ex)
        Verify that given Throwable (or any of its causes) is InterruptedException.
        Parameters:
        ex - Throwable
        Returns:
        true if ex is InterruptedException
      • rethrowAsIllegalStateException

        public static void rethrowAsIllegalStateException​(java.lang.Throwable cause)
        Throw an IllegalStateException with given exception as cause.
        Parameters:
        cause - the cause of IllegalStateException.