package com.github.markozajc.ef; import static com.github.markozajc.ef.Utilities.asUnchecked; import java.util.concurrent.Callable; import java.util.function.*; import javax.annotation.Nonnull; import com.github.markozajc.ef.biconsumer.*; import com.github.markozajc.ef.biconsumer.except.*; import com.github.markozajc.ef.bifunction.*; import com.github.markozajc.ef.bifunction.except.*; import com.github.markozajc.ef.bipredicate.*; import com.github.markozajc.ef.bipredicate.except.*; import com.github.markozajc.ef.consumer.*; import com.github.markozajc.ef.consumer.execpt.*; import com.github.markozajc.ef.function.*; import com.github.markozajc.ef.function.except.*; import com.github.markozajc.ef.predicate.*; import com.github.markozajc.ef.predicate.except.*; import com.github.markozajc.ef.runnable.except.ERunnable; import com.github.markozajc.ef.supplier.*; import com.github.markozajc.ef.supplier.except.*; import com.github.markozajc.ef.triconsumer.*; import com.github.markozajc.ef.trifunction.*; import com.github.markozajc.ef.tripredicate.*; /** * A class containing various helper utilities for exceptionable (E*) functions and * {@link Callable} ({@link ESupplier}). * * @author Marko Zajc */ public class EHandle { /* * ================== Consumers ================== */ /** * Handles a generic exception type that may occur in the handled consumer with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer */ @Nonnull public static Consumer handle(@Nonnull EConsumer handled, @Nonnull BiConsumer handler) { return t -> { try { handled.acceptChecked(t); } catch (Throwable e) { // NOSONAR can't catch generic exceptions handler.accept(e, t); } }; } /** * Handles a generic exception type that may occur in the handled consumer by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static Consumer handleThrowing(@Nonnull EConsumer handled, @Nonnull Function handler) throws X { return t -> { try { handled.acceptChecked(t); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled consumer by * throwing a different exception. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer */ @Nonnull public static BooleanConsumer handle(@Nonnull EBooleanConsumer handled, @Nonnull ObjBooleanConsumer handler) { return p -> { try { handled.acceptChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions handler.accept(e, p); } }; } /** * Handles a generic exception type that may occur in the handled consumer by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static BooleanConsumer handleThrowing(@Nonnull EBooleanConsumer handled, @Nonnull Function handler) throws X { return p -> { try { handled.acceptChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled consumer with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer */ @Nonnull public static ByteConsumer handle(@Nonnull EByteConsumer handled, @Nonnull ObjByteConsumer handler) { return p -> { try { handled.acceptChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions handler.accept(e, p); } }; } /** * Handles a generic exception type that may occur in the handled consumer by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ByteConsumer handleThrowing(@Nonnull EByteConsumer handled, @Nonnull Function handler) throws X { return p -> { try { handled.acceptChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled consumer with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer */ @Nonnull public static IntConsumer handle(@Nonnull EIntConsumer handled, @Nonnull ObjIntConsumer handler) { return p -> { try { handled.acceptChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions handler.accept(e, p); } }; } /** * Handles a generic exception type that may occur in the handled consumer by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static IntConsumer handleThrowing(@Nonnull EIntConsumer handled, @Nonnull Function handler) throws X { return p -> { try { handled.acceptChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled consumer with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer */ @Nonnull public static LongConsumer handle(@Nonnull ELongConsumer handled, @Nonnull ObjLongConsumer handler) { return p -> { try { handled.acceptChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions handler.accept(e, p); } }; } /** * Handles a generic exception type that may occur in the handled consumer by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static LongConsumer handleThrowing(@Nonnull ELongConsumer handled, @Nonnull Function handler) throws X { return p -> { try { handled.acceptChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled consumer with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer */ @Nonnull public static ShortConsumer handle(@Nonnull EShortConsumer handled, @Nonnull ObjShortConsumer handler) { return p -> { try { handled.acceptChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions handler.accept(e, p); } }; } /** * Handles a generic exception type that may occur in the handled consumer by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ShortConsumer handleThrowing(@Nonnull EShortConsumer handled, @Nonnull Function handler) throws X { return p -> { try { handled.acceptChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /* * ================== BiConsumers ================== */ /** * Handles a generic exception type that may occur in the handled consumer with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer */ @Nonnull public static BiConsumer handle(@Nonnull EBiConsumer handled, @Nonnull TriConsumer handler) { return (t, u) -> { try { handled.acceptChecked(t, u); } catch (Throwable e) { // NOSONAR can't catch generic exceptions handler.accept(e, t, u); } }; } /** * Handles a generic exception type that may occur in the handled consumer by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static BiConsumer handleThrowing(@Nonnull EBiConsumer handled, @Nonnull Function handler) throws X { return (t, u) -> { try { handled.acceptChecked(t, u); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled consumer with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer */ @Nonnull public static ObjBooleanConsumer handle(@Nonnull EObjBooleanConsumer handled, @Nonnull ObjObjBooleanConsumer handler) { return (t, p) -> { try { handled.acceptChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions handler.accept(e, t, p); } }; } /** * Handles a generic exception type that may occur in the handled consumer by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ObjBooleanConsumer handleThrowing(@Nonnull EObjBooleanConsumer handled, @Nonnull Function handler) throws X { return (t, p) -> { try { handled.acceptChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled consumer with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer */ @Nonnull public static ObjByteConsumer handle(@Nonnull EObjByteConsumer handled, @Nonnull ObjObjByteConsumer handler) { return (t, p) -> { try { handled.acceptChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions handler.accept(e, t, p); } }; } /** * Handles a generic exception type that may occur in the handled consumer by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ObjByteConsumer handleThrowing(@Nonnull EObjByteConsumer handled, @Nonnull Function handler) throws X { return (t, p) -> { try { handled.acceptChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled consumer with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer */ @Nonnull public static ObjIntConsumer handle(@Nonnull EObjIntConsumer handled, @Nonnull ObjObjIntConsumer handler) { return (t, p) -> { try { handled.acceptChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions handler.accept(e, t, p); } }; } /** * Handles a generic exception type that may occur in the handled consumer by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ObjIntConsumer handleThrowing(@Nonnull EObjIntConsumer handled, @Nonnull Function handler) throws X { return (t, p) -> { try { handled.acceptChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled consumer with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer */ @Nonnull public static ObjLongConsumer handle(@Nonnull EObjLongConsumer handled, @Nonnull ObjObjLongConsumer handler) { return (t, p) -> { try { handled.acceptChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions handler.accept(e, t, p); } }; } /** * Handles a generic exception type that may occur in the handled consumer by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ObjLongConsumer handleThrowing(@Nonnull EObjLongConsumer handled, @Nonnull Function handler) throws X { return (t, p) -> { try { handled.acceptChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled consumer with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer */ @Nonnull public static ObjShortConsumer handle(@Nonnull EObjShortConsumer handled, @Nonnull ObjObjShortConsumer handler) { return (t, p) -> { try { handled.acceptChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions handler.accept(e, t, p); } }; } /** * Handles a generic exception type that may occur in the handled consumer by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed consumer * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ObjShortConsumer handleThrowing(@Nonnull EObjShortConsumer handled, @Nonnull Function handler) throws X { return (t, p) -> { try { handled.acceptChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /* * ================== Functions ================== */ /** * Handles a generic exception type that may occur in the handled function with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function */ @Nonnull public static Function handle(@Nonnull EFunction handled, @Nonnull BiFunction handler) { return t -> { try { return handled.applyChecked(t); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.apply(e, t); } }; } /** * Handles a generic exception type that may occur in the handled function by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static Function handleThrowing(@Nonnull EFunction handled, @Nonnull Function handler) throws X { return t -> { try { return handled.applyChecked(t); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled function with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function */ @Nonnull public static BooleanFunction handle(@Nonnull EBooleanFunction handled, @Nonnull ObjBooleanFunction handler) { return p -> { try { return handled.applyChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.apply(e, p); } }; } /** * Handles a generic exception type that may occur in the handled function by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static BooleanFunction handleThrowing(@Nonnull EBooleanFunction handled, @Nonnull Function handler) throws X { return p -> { try { return handled.applyChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled function with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function */ @Nonnull public static ByteFunction handle(@Nonnull EByteFunction handled, @Nonnull ObjByteFunction handler) { return p -> { try { return handled.applyChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.apply(e, p); } }; } /** * Handles a generic exception type that may occur in the handled function by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ByteFunction handleThrowing(@Nonnull EByteFunction handled, @Nonnull Function handler) throws X { return p -> { try { return handled.applyChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled function with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function */ @Nonnull public static IntFunction handle(@Nonnull EIntFunction handled, @Nonnull ObjIntFunction handler) { return p -> { try { return handled.applyChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.apply(e, p); } }; } /** * Handles a generic exception type that may occur in the handled function by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static IntFunction handleThrowing(@Nonnull EIntFunction handled, @Nonnull Function handler) throws X { return p -> { try { return handled.applyChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled function with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function */ @Nonnull public static LongFunction handle(@Nonnull ELongFunction handled, @Nonnull ObjLongFunction handler) { return p -> { try { return handled.applyChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.apply(e, p); } }; } /** * Handles a generic exception type that may occur in the handled function by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static LongFunction handleThrowing(@Nonnull ELongFunction handled, @Nonnull Function handler) throws X { return p -> { try { return handled.applyChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled function with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function */ @Nonnull public static ShortFunction handle(@Nonnull EShortFunction handled, @Nonnull ObjShortFunction handler) { return p -> { try { return handled.applyChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.apply(e, p); } }; } /** * Handles a generic exception type that may occur in the handled function by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ShortFunction handleThrowing(@Nonnull EShortFunction handled, @Nonnull Function handler) throws X { return p -> { try { return handled.applyChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /* * ================== BiFunctions ================== */ /** * Handles a generic exception type that may occur in the handled function with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function */ @Nonnull public static BiFunction handle(@Nonnull EBiFunction handled, @Nonnull TriFunction handler) { return (t, u) -> { try { return handled.applyChecked(t, u); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.apply(e, t, u); } }; } /** * Handles a generic exception type that may occur in the handled function by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static BiFunction handleThrowing(@Nonnull EBiFunction handled, @Nonnull Function handler) throws X { return (t, u) -> { try { return handled.applyChecked(t, u); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled function with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function */ @Nonnull public static ObjBooleanFunction handle(@Nonnull EObjBooleanFunction handled, @Nonnull ObjObjBooleanFunction handler) { return (t, p) -> { try { return handled.applyChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.apply(e, t, p); } }; } /** * Handles a generic exception type that may occur in the handled function by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ObjBooleanFunction handleThrowing(@Nonnull EObjBooleanFunction handled, @Nonnull Function handler) throws X { return (t, p) -> { try { return handled.applyChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled function with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function */ @Nonnull public static ObjByteFunction handle(@Nonnull EObjByteFunction handled, @Nonnull ObjObjByteFunction handler) { return (t, p) -> { try { return handled.applyChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.apply(e, t, p); } }; } /** * Handles a generic exception type that may occur in the handled function by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ObjByteFunction handleThrowing(@Nonnull EObjByteFunction handled, @Nonnull Function handler) throws X { return (t, p) -> { try { return handled.applyChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled function with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function */ @Nonnull public static ObjIntFunction handle(@Nonnull EObjIntFunction handled, @Nonnull ObjObjIntFunction handler) { return (t, p) -> { try { return handled.applyChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.apply(e, t, p); } }; } /** * Handles a generic exception type that may occur in the handled function by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ObjIntFunction handleThrowing(@Nonnull EObjIntFunction handled, @Nonnull Function handler) throws X { return (t, p) -> { try { return handled.applyChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled function with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function */ @Nonnull public static ObjLongFunction handle(@Nonnull EObjLongFunction handled, @Nonnull ObjObjLongFunction handler) { return (t, p) -> { try { return handled.applyChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.apply(e, t, p); } }; } /** * Handles a generic exception type that may occur in the handled function by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ObjLongFunction handleThrowing(@Nonnull EObjLongFunction handled, @Nonnull Function handler) throws X { return (t, p) -> { try { return handled.applyChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled function with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function */ @Nonnull public static ObjShortFunction handle(@Nonnull EObjShortFunction handled, @Nonnull ObjObjShortFunction handler) { return (t, p) -> { try { return handled.applyChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.apply(e, t, p); } }; } /** * Handles a generic exception type that may occur in the handled function by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ObjShortFunction handleThrowing(@Nonnull EObjShortFunction handled, @Nonnull Function handler) throws X { return (t, p) -> { try { return handled.applyChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /* * ================== Predicates ================== */ /** * Handles a generic exception type that may occur in the handled predicate with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate */ @Nonnull public static Predicate handle(@Nonnull EPredicate handled, @Nonnull BiPredicate handler) { return t -> { try { return handled.testChecked(t); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.test(e, t); } }; } /** * Handles a generic exception type that may occur in the handled predicate by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static Predicate handleThrowing(@Nonnull EPredicate handled, @Nonnull Function handler) throws X { return t -> { try { return handled.testChecked(t); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled predicate with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate */ @Nonnull public static BooleanPredicate handle(@Nonnull EBooleanPredicate handled, @Nonnull ObjBooleanPredicate handler) { return p -> { try { return handled.testChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.test(e, p); } }; } /** * Handles a generic exception type that may occur in the handled predicate by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static BooleanPredicate handleThrowing(@Nonnull EBooleanPredicate handled, @Nonnull Function handler) throws X { return p -> { try { return handled.testChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled predicate with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate */ @Nonnull public static BytePredicate handle(@Nonnull EBytePredicate handled, @Nonnull ObjBytePredicate handler) { return p -> { try { return handled.testChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.test(e, p); } }; } /** * Handles a generic exception type that may occur in the handled predicate by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static BytePredicate handleThrowing(@Nonnull EBytePredicate handled, @Nonnull Function handler) throws X { return p -> { try { return handled.testChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled predicate with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate */ @Nonnull public static IntPredicate handle(@Nonnull EIntPredicate handled, @Nonnull ObjIntPredicate handler) { return p -> { try { return handled.testChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.test(e, p); } }; } /** * Handles a generic exception type that may occur in the handled predicate by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static IntPredicate handleThrowing(@Nonnull EIntPredicate handled, @Nonnull Function handler) throws X { return p -> { try { return handled.testChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled predicate with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate */ @Nonnull public static LongPredicate handle(@Nonnull ELongPredicate handled, @Nonnull ObjLongPredicate handler) { return p -> { try { return handled.testChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.test(e, p); } }; } /** * Handles a generic exception type that may occur in the handled predicate by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static LongPredicate handleThrowing(@Nonnull ELongPredicate handled, @Nonnull Function handler) throws X { return p -> { try { return handled.testChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled predicate with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate */ @Nonnull public static ShortPredicate handle(@Nonnull EShortPredicate handled, @Nonnull ObjShortPredicate handler) { return p -> { try { return handled.testChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.test(e, p); } }; } /** * Handles a generic exception type that may occur in the handled predicate by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ShortPredicate handleThrowing(@Nonnull EShortPredicate handled, @Nonnull Function handler) throws X { return p -> { try { return handled.testChecked(p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /* * ================== BiPredicates ================== */ /** * Handles a generic exception type that may occur in the handled predicate with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate */ @Nonnull public static BiPredicate handle(@Nonnull EBiPredicate handled, @Nonnull TriPredicate handler) { return (t, u) -> { try { return handled.testChecked(t, u); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.test(e, t, u); } }; } /** * Handles a generic exception type that may occur in the handled predicate by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static BiPredicate handleThrowing(@Nonnull EBiPredicate handled, @Nonnull Function handler) throws X { return (t, u) -> { try { return handled.testChecked(t, u); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled predicate with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate */ @Nonnull public static ObjBooleanPredicate handle(@Nonnull EObjBooleanPredicate handled, @Nonnull ObjObjBooleanPredicate handler) { return (t, p) -> { try { return handled.testChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.test(e, t, p); } }; } /** * Handles a generic exception type that may occur in the handled predicate by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ObjBooleanPredicate handleThrowing(@Nonnull EObjBooleanPredicate handled, @Nonnull Function handler) throws X { return (t, p) -> { try { return handled.testChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled predicate with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate */ @Nonnull public static ObjBytePredicate handle(@Nonnull EObjBytePredicate handled, @Nonnull ObjObjBytePredicate handler) { return (t, p) -> { try { return handled.testChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.test(e, t, p); } }; } /** * Handles a generic exception type that may occur in the handled predicate by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ObjBytePredicate handleThrowing(@Nonnull EObjBytePredicate handled, @Nonnull Function handler) throws X { return (t, p) -> { try { return handled.testChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled predicate with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate */ @Nonnull public static ObjIntPredicate handle(@Nonnull EObjIntPredicate handled, @Nonnull ObjObjIntPredicate handler) { return (t, p) -> { try { return handled.testChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.test(e, t, p); } }; } /** * Handles a generic exception type that may occur in the handled predicate by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ObjIntPredicate handleThrowing(@Nonnull EObjIntPredicate handled, @Nonnull Function handler) throws X { return (t, p) -> { try { return handled.testChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled predicate with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate */ @Nonnull public static ObjLongPredicate handle(@Nonnull EObjLongPredicate handled, @Nonnull ObjObjLongPredicate handler) { return (t, p) -> { try { return handled.testChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.test(e, t, p); } }; } /** * Handles a generic exception type that may occur in the handled predicate by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ObjLongPredicate handleThrowing(@Nonnull EObjLongPredicate handled, @Nonnull Function handler) throws X { return (t, p) -> { try { return handled.testChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled predicate with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate */ @Nonnull public static ObjShortPredicate handle(@Nonnull EObjShortPredicate handled, @Nonnull ObjObjShortPredicate handler) { return (t, p) -> { try { return handled.testChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.test(e, t, p); } }; } /** * Handles a generic exception type that may occur in the handled predicate by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed predicate * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ObjShortPredicate handleThrowing(@Nonnull EObjShortPredicate handled, @Nonnull Function handler) throws X { return (t, p) -> { try { return handled.testChecked(t, p); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /* * ================== Runnables ================== */ /** * Handles a generic exception type that may occur in the handled runnable with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed runnable */ @Nonnull public static Runnable handle(@Nonnull ERunnable handled, @Nonnull Consumer handler) { return () -> { try { handled.runChecked(); } catch (Throwable e) { // NOSONAR can't catch generic exceptions handler.accept(e); } }; } /** * Handles a generic exception type that may occur in the handled runnable by * throwing a different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed runnable * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static Runnable handleThrowing(@Nonnull ERunnable handled, @Nonnull Function handler) throws X { return () -> { try { handled.runChecked(); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /* * ================== Suppliers & Callable ================== */ /** * Handles any exception type that may occur in the handled callable with a provided * handler. * * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed callable */ @Nonnull public static Supplier handle(@Nonnull Callable handled, @Nonnull Function handler) { return () -> { try { return handled.call(); } catch (Exception e) { return handler.apply(e); } }; } /** * Handles any exception type that may occur in the handled callable by throwing a * different exception. * * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed callable * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static Supplier handleThrowing(@Nonnull Callable handled, @Nonnull Function handler) throws X { return () -> { try { return handled.call(); } catch (Exception e) { throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled function with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function */ @Nonnull public static Supplier handle(@Nonnull ESupplier handled, @Nonnull Function handler) { return () -> { try { return handled.getChecked(); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.apply(e); } }; } /** * Handles any exception types that may occur in the handled supplier by throwing a * different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed supplier * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static Supplier handleThrowing(@Nonnull ESupplier handled, @Nonnull Function handler) throws X { return () -> { try { return handled.getChecked(); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled function with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function */ @Nonnull public static BooleanSupplier handle(@Nonnull EBooleanSupplier handled, @Nonnull Predicate handler) { return () -> { try { return handled.getAsBoolean(); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.test(e); } }; } /** * Handles any exception types that may occur in the handled supplier by throwing a * different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed supplier * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static BooleanSupplier handleThrowing(@Nonnull EBooleanSupplier handled, @Nonnull Function handler) throws X { return () -> { try { return handled.getAsBoolean(); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } // missing: handle EByteSupplier, blocked by: missing ToByteFunction /** * Handles any exception types that may occur in the handled supplier by throwing a * different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed supplier * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ByteSupplier handleThrowing(@Nonnull EByteSupplier handled, @Nonnull Function handler) throws X { return () -> { try { return handled.getAsByte(); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled function with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function */ @Nonnull public static IntSupplier handle(@Nonnull EIntSupplier handled, @Nonnull ToIntFunction handler) { return () -> { try { return handled.getAsInt(); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.applyAsInt(e); } }; } /** * Handles any exception types that may occur in the handled supplier by throwing a * different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed supplier * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static IntSupplier handleThrowing(@Nonnull EIntSupplier handled, @Nonnull Function handler) throws X { return () -> { try { return handled.getAsInt(); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } // missing: handle EShortSupplier, blocked by: missing ToShortFunction /** * Handles any exception types that may occur in the handled supplier by throwing a * different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed supplier * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static ShortSupplier handleThrowing(@Nonnull EShortSupplier handled, @Nonnull Function handler) throws X { return () -> { try { return handled.getAsShort(); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } /** * Handles a generic exception type that may occur in the handled function with a * provided handler. * * @param * The handled function's exception type * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed function */ @Nonnull public static LongSupplier handle(@Nonnull ELongSupplier handled, @Nonnull ToLongFunction handler) { return () -> { try { return handled.getAsLong(); } catch (Throwable e) { // NOSONAR can't catch generic exceptions return handler.applyAsLong(e); } }; } /** * Handles any exception types that may occur in the handled supplier by throwing a * different exception. * * @param * The handled function's exception type * @param * The exception type to throw * @param handled * The function that may throw an exception * @param handler * The function handling exceptions * * @return An exception-proofed supplier * * @throws X * The exception returned by the handler */ @Nonnull @SuppressWarnings({ "null", "unused" }) public static LongSupplier handleThrowing(@Nonnull ELongSupplier handled, @Nonnull Function handler) throws X { return () -> { try { return handled.getAsLong(); } catch (Throwable e) { // NOSONAR can't catch generic exceptions throw asUnchecked(handler.apply(e)); } }; } private EHandle() {} }