Package nl.vpro.util

Class ExceptionUtils


  • public class ExceptionUtils
    extends Object
    Since:
    1.78
    Author:
    Michiel Meeuwissen
    • Constructor Detail

      • ExceptionUtils

        public ExceptionUtils()
    • Method Detail

      • wrapException

        public static <T> Supplier<T> wrapException​(Callable<T> b)
        Wraps a Callable in a Supplier.

        You may need a supplier, but have code that throws an exception. Like this:

        service.download(file, ExceptionUtils.wrapException(() -> new FileOutputStream(destFile))) The point is that otherwise this nice lambda gets ugly because of the try/catch block.

      • wrapConsumer

        public static <T> Consumer<T> wrapConsumer​(org.meeuw.functional.ThrowingConsumer<T,​?> b)
        Wraps a Callable in a Supplier.

        You may need a supplier, but have code that throws an exception. Like this:

        service.download(file, ExceptionUtils.wrapException(() -> new FileOutputStream(destFile))) The point is that otherwise this nice lambda gets ugly because of the try/catch block.