com.machinezoo.noexception

Class ExceptionHandler

NoException » API Reference » com.machinezoo.noexception



  • public abstract class ExceptionHandler
    extends Object
    Represents exception handling policy. Methods of this class apply the exception policy to functional interfaces (usually lambdas) by wrapping them in a try-catch block. Method handle(Throwable) defines the exception handling policy when implemented in derived class. See noexception tutorial.
    Typical usage: Exceptions.log().get(() -> my_throwing_lambda).orElse(fallback)
    All wrapping methods surround the functional interface with a try-catch block. If the functional interface throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null functional interface is caught too. Unless handle(Throwable) requests a rethrow, void functional interfaces complete normally while non-void functional interfaces return empty Optional.
    Wrapping methods for all standard functional interfaces are provided. Simple interfaces have short method names like runnable(Runnable) or supplier(Supplier). Interfaces with longer names have methods that follow fromX naming pattern, for example fromUnaryOperator(UnaryOperator). Parameterless functional interfaces can be called directly by methods run(Runnable), get(Supplier), and the various getAsX variants.
    All non-void wrappers conform to some OptionalX functional interface, for example OptionalSupplier, that is identical to its non-optional variant from JDK except it returns Optional instead of raw value. This Optional is empty in case of exception. Callers can use Optional.orElse(Object) and Optional.orElseGet(Supplier) and their equivalents on OptionalX interfaces to provide fallback values.
    See Also:
    Tutorial, handle(Throwable), Exceptions, OptionalSupplier, Optional, CheckedExceptionHandler
    • Constructor Detail

      • ExceptionHandler

        protected ExceptionHandler()
        Initialize new ExceptionHandler.
    • Method Detail

      • handle

        public abstract boolean handle(Throwable exception)
        Handle exception in a generic way. This method must be defined in a derived class. Several implementations are provided by methods on Exceptions class. All other methods of the ExceptionHandler call this method, but it can be also called directly.
        This method represents reusable catch block that handles all exceptions in the same way. When invoked, it must somehow handle the provided exception, for example by logging it.
        This method does not have to handle all exceptions. It can indicate through return value whether it has accepted or rejected the exception. When an exception is rejected, caller of this method is expected to rethrow the exception. All other methods of this class fulfill this requirement.
        Parameters:
        exception - the exception to handle
        Returns:
        true when exception is handled, false if the exception should be rethrown
        Throws:
        NullPointerException - if exception is null
        See Also:
        Tutorial, Exceptions
      • runnable

        public final Runnable runnable(Runnable runnable)
        Wraps Runnable in a try-catch block.
        If runnable throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null runnable is caught too. Wrapper then completes normally unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().runnable(() -> my_throwing_lambda)
        Parameters:
        runnable - the Runnable to wrap, usually a lambda
        Returns:
        wrapper that runs runnable in a try-catch block
        See Also:
        Tutorial, Exceptions
      • supplier

        public final <T> OptionalSupplier<T> supplier(Supplier<T> supplier)
        Wraps Supplier in a try-catch block.
        If supplier throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null supplier is caught too. Wrapper then returns empty Optional unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().supplier(() -> my_throwing_lambda).orElse(fallback)
        Parameters:
        supplier - the Supplier to wrap, usually a lambda
        Returns:
        wrapper that runs supplier in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromIntSupplier

        public final OptionalIntSupplier fromIntSupplier(IntSupplier supplier)
        Wraps IntSupplier in a try-catch block.
        If supplier throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null supplier is caught too. Wrapper then returns empty OptionalInt unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromIntSupplier(() -> my_throwing_lambda).orElse(fallback)
        Parameters:
        supplier - the IntSupplier to wrap, usually a lambda
        Returns:
        wrapper that runs supplier in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromLongSupplier

        public final OptionalLongSupplier fromLongSupplier(LongSupplier supplier)
        Wraps LongSupplier in a try-catch block.
        If supplier throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null supplier is caught too. Wrapper then returns empty OptionalLong unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromLongSupplier(() -> my_throwing_lambda).orElse(fallback)
        Parameters:
        supplier - the LongSupplier to wrap, usually a lambda
        Returns:
        wrapper that runs supplier in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromDoubleSupplier

        public final OptionalDoubleSupplier fromDoubleSupplier(DoubleSupplier supplier)
        Wraps DoubleSupplier in a try-catch block.
        If supplier throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null supplier is caught too. Wrapper then returns empty OptionalDouble unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromDoubleSupplier(() -> my_throwing_lambda).orElse(fallback)
        Parameters:
        supplier - the DoubleSupplier to wrap, usually a lambda
        Returns:
        wrapper that runs supplier in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromBooleanSupplier

        public final OptionalBooleanSupplier fromBooleanSupplier(BooleanSupplier supplier)
        Wraps BooleanSupplier in a try-catch block.
        If supplier throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null supplier is caught too. Wrapper then returns empty OptionalBoolean unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromBooleanSupplier(() -> my_throwing_lambda).orElse(fallback)
        Parameters:
        supplier - the BooleanSupplier to wrap, usually a lambda
        Returns:
        wrapper that runs supplier in a try-catch block
        See Also:
        Tutorial, Exceptions
      • consumer

        public final <T> Consumer<T> consumer(Consumer<T> consumer)
        Wraps Consumer in a try-catch block.
        If consumer throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null consumer is caught too. Wrapper then completes normally unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().consumer(t -> my_throwing_lambda)
        Parameters:
        consumer - the Consumer to wrap, usually a lambda
        Returns:
        wrapper that runs consumer in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromIntConsumer

        public final IntConsumer fromIntConsumer(IntConsumer consumer)
        Wraps IntConsumer in a try-catch block.
        If consumer throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null consumer is caught too. Wrapper then completes normally unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromIntConsumer(v -> my_throwing_lambda)
        Parameters:
        consumer - the IntConsumer to wrap, usually a lambda
        Returns:
        wrapper that runs consumer in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromLongConsumer

        public final LongConsumer fromLongConsumer(LongConsumer consumer)
        Wraps LongConsumer in a try-catch block.
        If consumer throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null consumer is caught too. Wrapper then completes normally unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromLongConsumer(v -> my_throwing_lambda)
        Parameters:
        consumer - the LongConsumer to wrap, usually a lambda
        Returns:
        wrapper that runs consumer in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromDoubleConsumer

        public final DoubleConsumer fromDoubleConsumer(DoubleConsumer consumer)
        Wraps DoubleConsumer in a try-catch block.
        If consumer throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null consumer is caught too. Wrapper then completes normally unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromDoubleConsumer(v -> my_throwing_lambda)
        Parameters:
        consumer - the DoubleConsumer to wrap, usually a lambda
        Returns:
        wrapper that runs consumer in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromBiConsumer

        public final <T,U> BiConsumer<T,U> fromBiConsumer(BiConsumer<T,U> consumer)
        Wraps BiConsumer in a try-catch block.
        If consumer throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null consumer is caught too. Wrapper then completes normally unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromBiConsumer((t, u) -> my_throwing_lambda)
        Parameters:
        consumer - the BiConsumer to wrap, usually a lambda
        Returns:
        wrapper that runs consumer in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromObjIntConsumer

        public final <T> ObjIntConsumer<T> fromObjIntConsumer(ObjIntConsumer<T> consumer)
        Wraps ObjIntConsumer in a try-catch block.
        If consumer throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null consumer is caught too. Wrapper then completes normally unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromObjIntConsumer((t, v) -> my_throwing_lambda)
        Parameters:
        consumer - the ObjIntConsumer to wrap, usually a lambda
        Returns:
        wrapper that runs consumer in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromObjLongConsumer

        public final <T> ObjLongConsumer<T> fromObjLongConsumer(ObjLongConsumer<T> consumer)
        Wraps ObjLongConsumer in a try-catch block.
        If consumer throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null consumer is caught too. Wrapper then completes normally unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromObjLongConsumer((t, v) -> my_throwing_lambda)
        Parameters:
        consumer - the ObjLongConsumer to wrap, usually a lambda
        Returns:
        wrapper that runs consumer in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromObjDoubleConsumer

        public final <T> ObjDoubleConsumer<T> fromObjDoubleConsumer(ObjDoubleConsumer<T> consumer)
        Wraps ObjDoubleConsumer in a try-catch block.
        If consumer throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null consumer is caught too. Wrapper then completes normally unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromObjDoubleConsumer((t, v) -> my_throwing_lambda)
        Parameters:
        consumer - the ObjDoubleConsumer to wrap, usually a lambda
        Returns:
        wrapper that runs consumer in a try-catch block
        See Also:
        Tutorial, Exceptions
      • predicate

        public final <T> OptionalPredicate<T> predicate(Predicate<T> predicate)
        Wraps Predicate in a try-catch block.
        If predicate throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null predicate is caught too. Wrapper then returns empty OptionalBoolean unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().predicate(t -> my_throwing_lambda).orElse(fallback)
        Parameters:
        predicate - the Predicate to wrap, usually a lambda
        Returns:
        wrapper that runs predicate in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromIntPredicate

        public final OptionalIntPredicate fromIntPredicate(IntPredicate predicate)
        Wraps IntPredicate in a try-catch block.
        If predicate throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null predicate is caught too. Wrapper then returns empty OptionalBoolean unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromIntPredicate(v -> my_throwing_lambda).orElse(fallback)
        Parameters:
        predicate - the IntPredicate to wrap, usually a lambda
        Returns:
        wrapper that runs predicate in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromLongPredicate

        public final OptionalLongPredicate fromLongPredicate(LongPredicate predicate)
        Wraps LongPredicate in a try-catch block.
        If predicate throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null predicate is caught too. Wrapper then returns empty OptionalBoolean unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromLongPredicate(v -> my_throwing_lambda).orElse(fallback)
        Parameters:
        predicate - the LongPredicate to wrap, usually a lambda
        Returns:
        wrapper that runs predicate in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromDoublePredicate

        public final OptionalDoublePredicate fromDoublePredicate(DoublePredicate predicate)
        Wraps DoublePredicate in a try-catch block.
        If predicate throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null predicate is caught too. Wrapper then returns empty OptionalBoolean unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromDoublePredicate(v -> my_throwing_lambda).orElse(fallback)
        Parameters:
        predicate - the DoublePredicate to wrap, usually a lambda
        Returns:
        wrapper that runs predicate in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromBiPredicate

        public final <T,U> OptionalBiPredicate<T,U> fromBiPredicate(BiPredicate<T,U> predicate)
        Wraps BiPredicate in a try-catch block.
        If predicate throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null predicate is caught too. Wrapper then returns empty OptionalBoolean unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromBiPredicate((t, u) -> my_throwing_lambda).orElse(fallback)
        Parameters:
        predicate - the BiPredicate to wrap, usually a lambda
        Returns:
        wrapper that runs predicate in a try-catch block
        See Also:
        Tutorial, Exceptions
      • function

        public final <T,R> OptionalFunction<T,R> function(Function<T,R> function)
        Wraps Function in a try-catch block.
        If function throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null function is caught too. Wrapper then returns empty Optional unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().function(t -> my_throwing_lambda).orElse(fallback)
        Parameters:
        function - the Function to wrap, usually a lambda
        Returns:
        wrapper that runs function in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromToIntFunction

        public final <T> OptionalToIntFunction<T> fromToIntFunction(ToIntFunction<T> function)
        Wraps ToIntFunction in a try-catch block.
        If function throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null function is caught too. Wrapper then returns empty OptionalInt unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromToIntFunction(v -> my_throwing_lambda).orElse(fallback)
        Parameters:
        function - the ToIntFunction to wrap, usually a lambda
        Returns:
        wrapper that runs function in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromIntFunction

        public final <R> OptionalIntFunction<R> fromIntFunction(IntFunction<R> function)
        Wraps IntFunction in a try-catch block.
        If function throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null function is caught too. Wrapper then returns empty Optional unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromIntFunction(v -> my_throwing_lambda).orElse(fallback)
        Parameters:
        function - the IntFunction to wrap, usually a lambda
        Returns:
        wrapper that runs function in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromIntToLongFunction

        public final OptionalIntToLongFunction fromIntToLongFunction(IntToLongFunction function)
        Wraps IntToLongFunction in a try-catch block.
        If function throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null function is caught too. Wrapper then returns empty OptionalLong unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromIntToLongFunction(v -> my_throwing_lambda).orElse(fallback)
        Parameters:
        function - the IntToLongFunction to wrap, usually a lambda
        Returns:
        wrapper that runs function in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromIntToDoubleFunction

        public final OptionalIntToDoubleFunction fromIntToDoubleFunction(IntToDoubleFunction function)
        Wraps IntToDoubleFunction in a try-catch block.
        If function throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null function is caught too. Wrapper then returns empty OptionalDouble unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromIntToDoubleFunction(v -> my_throwing_lambda).orElse(fallback)
        Parameters:
        function - the IntToDoubleFunction to wrap, usually a lambda
        Returns:
        wrapper that runs function in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromToLongFunction

        public final <T> OptionalToLongFunction<T> fromToLongFunction(ToLongFunction<T> function)
        Wraps ToLongFunction in a try-catch block.
        If function throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null function is caught too. Wrapper then returns empty OptionalLong unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromToLongFunction(v -> my_throwing_lambda).orElse(fallback)
        Parameters:
        function - the ToLongFunction to wrap, usually a lambda
        Returns:
        wrapper that runs function in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromLongFunction

        public final <R> OptionalLongFunction<R> fromLongFunction(LongFunction<R> function)
        Wraps LongFunction in a try-catch block.
        If function throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null function is caught too. Wrapper then returns empty Optional unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromLongFunction(v -> my_throwing_lambda).orElse(fallback)
        Parameters:
        function - the LongFunction to wrap, usually a lambda
        Returns:
        wrapper that runs function in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromLongToIntFunction

        public final OptionalLongToIntFunction fromLongToIntFunction(LongToIntFunction function)
        Wraps LongToIntFunction in a try-catch block.
        If function throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null function is caught too. Wrapper then returns empty OptionalInt unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromLongToIntFunction(v -> my_throwing_lambda).orElse(fallback)
        Parameters:
        function - the LongToIntFunction to wrap, usually a lambda
        Returns:
        wrapper that runs function in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromLongToDoubleFunction

        public final OptionalLongToDoubleFunction fromLongToDoubleFunction(LongToDoubleFunction function)
        Wraps LongToDoubleFunction in a try-catch block.
        If function throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null function is caught too. Wrapper then returns empty OptionalDouble unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromLongToDoubleFunction(v -> my_throwing_lambda).orElse(fallback)
        Parameters:
        function - the LongToDoubleFunction to wrap, usually a lambda
        Returns:
        wrapper that runs function in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromToDoubleFunction

        public final <T> OptionalToDoubleFunction<T> fromToDoubleFunction(ToDoubleFunction<T> function)
        Wraps ToDoubleFunction in a try-catch block.
        If function throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null function is caught too. Wrapper then returns empty OptionalDouble unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromToDoubleFunction(v -> my_throwing_lambda).orElse(fallback)
        Parameters:
        function - the ToDoubleFunction to wrap, usually a lambda
        Returns:
        wrapper that runs function in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromDoubleFunction

        public final <R> OptionalDoubleFunction<R> fromDoubleFunction(DoubleFunction<R> function)
        Wraps DoubleFunction in a try-catch block.
        If function throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null function is caught too. Wrapper then returns empty Optional unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromDoubleFunction(v -> my_throwing_lambda).orElse(fallback)
        Parameters:
        function - the DoubleFunction to wrap, usually a lambda
        Returns:
        wrapper that runs function in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromDoubleToIntFunction

        public final OptionalDoubleToIntFunction fromDoubleToIntFunction(DoubleToIntFunction function)
        Wraps DoubleToIntFunction in a try-catch block.
        If function throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null function is caught too. Wrapper then returns empty OptionalInt unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromDoubleToIntFunction(v -> my_throwing_lambda).orElse(fallback)
        Parameters:
        function - the DoubleToIntFunction to wrap, usually a lambda
        Returns:
        wrapper that runs function in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromDoubleToLongFunction

        public final OptionalDoubleToLongFunction fromDoubleToLongFunction(DoubleToLongFunction function)
        Wraps DoubleToLongFunction in a try-catch block.
        If function throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null function is caught too. Wrapper then returns empty OptionalLong unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromDoubleToLongFunction(v -> my_throwing_lambda).orElse(fallback)
        Parameters:
        function - the DoubleToLongFunction to wrap, usually a lambda
        Returns:
        wrapper that runs function in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromUnaryOperator

        public final <T> OptionalUnaryOperator<T> fromUnaryOperator(UnaryOperator<T> operator)
        Wraps UnaryOperator in a try-catch block.
        If operator throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null operator is caught too. Wrapper then returns empty Optional unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromUnaryOperator(o -> my_throwing_lambda).orElse(fallback)
        Parameters:
        operator - the UnaryOperator to wrap, usually a lambda
        Returns:
        wrapper that runs operator in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromIntUnaryOperator

        public final OptionalIntUnaryOperator fromIntUnaryOperator(IntUnaryOperator operator)
        Wraps IntUnaryOperator in a try-catch block.
        If operator throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null operator is caught too. Wrapper then returns empty OptionalInt unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromIntUnaryOperator(o -> my_throwing_lambda).orElse(fallback)
        Parameters:
        operator - the IntUnaryOperator to wrap, usually a lambda
        Returns:
        wrapper that runs operator in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromLongUnaryOperator

        public final OptionalLongUnaryOperator fromLongUnaryOperator(LongUnaryOperator operator)
        Wraps LongUnaryOperator in a try-catch block.
        If operator throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null operator is caught too. Wrapper then returns empty OptionalLong unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromLongUnaryOperator(o -> my_throwing_lambda).orElse(fallback)
        Parameters:
        operator - the LongUnaryOperator to wrap, usually a lambda
        Returns:
        wrapper that runs operator in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromDoubleUnaryOperator

        public final OptionalDoubleUnaryOperator fromDoubleUnaryOperator(DoubleUnaryOperator operator)
        Wraps DoubleUnaryOperator in a try-catch block.
        If operator throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null operator is caught too. Wrapper then returns empty OptionalDouble unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromDoubleUnaryOperator(o -> my_throwing_lambda).orElse(fallback)
        Parameters:
        operator - the DoubleUnaryOperator to wrap, usually a lambda
        Returns:
        wrapper that runs operator in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromBiFunction

        public final <T,U,R> OptionalBiFunction<T,U,R> fromBiFunction(BiFunction<T,U,R> function)
        Wraps BiFunction in a try-catch block.
        If function throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null function is caught too. Wrapper then returns empty Optional unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromBiFunction((t, u) -> my_throwing_lambda).orElse(fallback)
        Parameters:
        function - the BiFunction to wrap, usually a lambda
        Returns:
        wrapper that runs function in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromToIntBiFunction

        public final <T,U> OptionalToIntBiFunction<T,U> fromToIntBiFunction(ToIntBiFunction<T,U> function)
        Wraps ToIntBiFunction in a try-catch block.
        If function throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null function is caught too. Wrapper then returns empty OptionalInt unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromToIntBiFunction((t, u) -> my_throwing_lambda).orElse(fallback)
        Parameters:
        function - the ToIntBiFunction to wrap, usually a lambda
        Returns:
        wrapper that runs function in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromToLongBiFunction

        public final <T,U> OptionalToLongBiFunction<T,U> fromToLongBiFunction(ToLongBiFunction<T,U> function)
        Wraps ToLongBiFunction in a try-catch block.
        If function throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null function is caught too. Wrapper then returns empty OptionalLong unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromToLongBiFunction((t, u) -> my_throwing_lambda).orElse(fallback)
        Parameters:
        function - the ToLongBiFunction to wrap, usually a lambda
        Returns:
        wrapper that runs function in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromToDoubleBiFunction

        public final <T,U> OptionalToDoubleBiFunction<T,U> fromToDoubleBiFunction(ToDoubleBiFunction<T,U> function)
        Wraps ToDoubleBiFunction in a try-catch block.
        If function throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null function is caught too. Wrapper then returns empty OptionalDouble unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromToDoubleBiFunction((t, u) -> my_throwing_lambda).orElse(fallback)
        Parameters:
        function - the ToDoubleBiFunction to wrap, usually a lambda
        Returns:
        wrapper that runs function in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromBinaryOperator

        public final <T> OptionalBinaryOperator<T> fromBinaryOperator(BinaryOperator<T> operator)
        Wraps BinaryOperator in a try-catch block.
        If operator throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null operator is caught too. Wrapper then returns empty Optional unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromBinaryOperator((l, r) -> my_throwing_lambda).orElse(fallback)
        Parameters:
        operator - the BinaryOperator to wrap, usually a lambda
        Returns:
        wrapper that runs operator in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromIntBinaryOperator

        public final OptionalIntBinaryOperator fromIntBinaryOperator(IntBinaryOperator operator)
        Wraps IntBinaryOperator in a try-catch block.
        If operator throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null operator is caught too. Wrapper then returns empty OptionalInt unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromIntBinaryOperator((l, r) -> my_throwing_lambda).orElse(fallback)
        Parameters:
        operator - the IntBinaryOperator to wrap, usually a lambda
        Returns:
        wrapper that runs operator in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromLongBinaryOperator

        public final OptionalLongBinaryOperator fromLongBinaryOperator(LongBinaryOperator operator)
        Wraps LongBinaryOperator in a try-catch block.
        If operator throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null operator is caught too. Wrapper then returns empty OptionalLong unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromLongBinaryOperator((l, r) -> my_throwing_lambda).orElse(fallback)
        Parameters:
        operator - the LongBinaryOperator to wrap, usually a lambda
        Returns:
        wrapper that runs operator in a try-catch block
        See Also:
        Tutorial, Exceptions
      • fromDoubleBinaryOperator

        public final OptionalDoubleBinaryOperator fromDoubleBinaryOperator(DoubleBinaryOperator operator)
        Wraps DoubleBinaryOperator in a try-catch block.
        If operator throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null operator is caught too. Wrapper then returns empty OptionalDouble unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().fromDoubleBinaryOperator((l, r) -> my_throwing_lambda).orElse(fallback)
        Parameters:
        operator - the DoubleBinaryOperator to wrap, usually a lambda
        Returns:
        wrapper that runs operator in a try-catch block
        See Also:
        Tutorial, Exceptions
      • comparator

        public final <T> OptionalComparator<T> comparator(Comparator<T> comparator)
        Wraps Comparator in a try-catch block.
        If comparator throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null comparator is caught too. Wrapper then returns empty OptionalInt unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().comparator((l, r) -> my_throwing_lambda).orElse(fallback)
        Parameters:
        comparator - the Comparator to wrap, usually a lambda
        Returns:
        wrapper that runs comparator in a try-catch block
        See Also:
        Tutorial, Exceptions
      • run

        public final void run(Runnable runnable)
        Runs Runnable in a try-catch block.
        If runnable throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null runnable is caught too. This method then completes normally unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().run(() -> my_throwing_lambda)
        Parameters:
        runnable - the Runnable to run, usually a lambda
        See Also:
        Tutorial, Exceptions
      • get

        public final <T> Optional<T> get(Supplier<T> supplier)
        Runs Supplier in a try-catch block.
        If supplier throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null supplier is caught too. This method then returns empty Optional unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().get(() -> my_throwing_lambda)
        Parameters:
        supplier - the Supplier to run, usually a lambda
        Returns:
        an Optional carrying supplier result or an empty Optional if exception was caught
        See Also:
        Tutorial, Exceptions
      • getAsInt

        public final OptionalInt getAsInt(IntSupplier supplier)
        Runs IntSupplier in a try-catch block.
        If supplier throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null supplier is caught too. This method then returns empty OptionalInt unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().getAsInt(() -> my_throwing_lambda)
        Parameters:
        supplier - the IntSupplier to run, usually a lambda
        Returns:
        an OptionalInt carrying supplier result or an empty OptionalInt if exception was caught
        See Also:
        Tutorial, Exceptions
      • getAsLong

        public final OptionalLong getAsLong(LongSupplier supplier)
        Runs LongSupplier in a try-catch block.
        If supplier throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null supplier is caught too. This method then returns empty OptionalLong unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().getAsLong(() -> my_throwing_lambda)
        Parameters:
        supplier - the LongSupplier to run, usually a lambda
        Returns:
        an OptionalLong carrying supplier result or an empty OptionalLong if exception was caught
        See Also:
        Tutorial, Exceptions
      • getAsDouble

        public final OptionalDouble getAsDouble(DoubleSupplier supplier)
        Runs DoubleSupplier in a try-catch block.
        If supplier throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null supplier is caught too. This method then returns empty OptionalDouble unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().getAsDouble(() -> my_throwing_lambda)
        Parameters:
        supplier - the DoubleSupplier to run, usually a lambda
        Returns:
        an OptionalDouble carrying supplier result or an empty OptionalDouble if exception was caught
        See Also:
        Tutorial, Exceptions
      • getAsBoolean

        public final OptionalBoolean getAsBoolean(BooleanSupplier supplier)
        Runs BooleanSupplier in a try-catch block.
        If supplier throws, the exception is caught and passed to handle(Throwable), which applies exception handling policy (log, ignore, pass, custom). NullPointerException from null supplier is caught too. This method then returns empty OptionalBoolean unless handle(Throwable) requests a rethrow.
        Typical usage: Exceptions.log().getAsBoolean(() -> my_throwing_lambda)
        Parameters:
        supplier - the BooleanSupplier to run, usually a lambda
        Returns:
        an OptionalBoolean carrying supplier result or an empty OptionalBoolean if exception was caught
        See Also:
        Tutorial, Exceptions