Class LambdaExceptionUtils


  • public final class LambdaExceptionUtils
    extends Object
    A Utility which provides a way to throw checked exceptions from the lambda expressions.
    • Constructor Detail

      • LambdaExceptionUtils

        public LambdaExceptionUtils()
    • Method Detail

      • rethrowConsumer

        public static <T,​E extends ExceptionConsumer<T> rethrowConsumer​(LambdaExceptionUtils.ConsumerWithExceptions<T,​E> consumer)
        This method allows a Consumer which throws exceptions to be used in places which expects a Consumer.
        Type Parameters:
        T - the type of the input to the function
        E - the type of Exception
        Parameters:
        consumer - instances of the ConsumerWithExceptions functional interface
        Returns:
        an instance of the Consumer
      • rethrowBiConsumer

        public static <T,​U,​E extends ExceptionBiConsumer<T,​U> rethrowBiConsumer​(LambdaExceptionUtils.BiConsumerWithExceptions<T,​U,​E> biConsumer)
        This method allows a BiConsumer which throws exceptions to be used in places which expects a BiConsumer.
        Type Parameters:
        T - the type of the input to the function
        U - the type of the input to the function
        E - the type of Exception
        Parameters:
        biConsumer - instances of the BiConsumerWithExceptions functional interface
        Returns:
        an instance of the BiConsumer
      • rethrowFunction

        public static <T,​R,​E extends ExceptionFunction<T,​R> rethrowFunction​(LambdaExceptionUtils.FunctionWithExceptions<T,​R,​E> function)
        This method allows a Function which throws exceptions to be used in places which expects a Function.
        Type Parameters:
        T - Any Object.
        R - Any Object
        E - Any Exception.
        Parameters:
        function - Function to apply for given arguments.
        Returns:
        Any Object that result from the function passed.
      • rethrowSupplier

        public static <T,​E extends ExceptionSupplier<T> rethrowSupplier​(LambdaExceptionUtils.SupplierWithExceptions<T,​E> function)
        This method allows a Supplier which throws exceptions to be used in places which expects a Supplier.
        Type Parameters:
        T - Any Object.
        E - Any Exception.
        Parameters:
        function - Function to apply for given arguments.
        Returns:
        Supplier of the results.