- java.lang.Object
-
- com.machinezoo.noexception.ExceptionHandler
-
@ApiIssue("GitHub issue #3: Add wrapped(), sneaked(), and checked(handler) that return CombinedExceptionHandler (checked -> optional).") @ApiIssue("Add only/except(Predicate<Throwable>), which return handler that rethrows selected exceptions without passing them to handle().") 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. Methodhandle(Throwable)defines the exception handling policy when implemented in derived class. See noexception tutorial.Typical usage:
Exceptions.silence().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 (silence, propagate, logging, custom).NullPointerExceptionfromnullfunctional interface is caught too. Unlesshandle(Throwable)requests a rethrow, void functional interfaces complete normally while non-void functional interfaces return emptyOptional.Wrapping methods for all standard functional interfaces are provided. Simple interfaces have short method names like
runnable(Runnable)orsupplier(Supplier). Interfaces with longer names have methods that followfromXnaming pattern, for examplefromUnaryOperator(UnaryOperator). Parameterless functional interfaces can be called directly by methodsrun(Runnable),get(Supplier), and the variousgetAsXvariants.All non-void wrappers conform to some
OptionalXfunctional interface, for exampleOptionalSupplier, that is identical to its non-optional variant from JDK except it returnsOptionalinstead of raw value. ThisOptionalis empty in case of exception. Callers can useOptional.orElse(Object)andOptional.orElseGet(Supplier)and their equivalents onOptionalXinterfaces to provide fallback values.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedExceptionHandler()Initialize newExceptionHandler.
-
Method Summary
-
-
-
Method Detail
-
handle
public abstract boolean handle(Throwable exception)
Handles exception in a generic way. This method must be defined in a derived class. Several implementations are provided by methods onExceptionsclass. All other methods of theExceptionHandlercall 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:
-
truewhen exception is handled,falseif the exception should be rethrown - Throws:
-
NullPointerException- ifexceptionisnull - See Also:
-
Tutorial,
Exceptions
-
passing
public ExceptionFilter passing()
Adds a pass-through modifier to this exception handler. If this exception handler performs an action (like logging) and then stops exception propagation, this method will returnExceptionFilterthat performs the same action but additionally rethrows the exception.Reusable exception handlers can be defined once as
ExceptionHandlerinstances and then transformed intoExceptionFilterby this method when needed.If method
handle(Throwable)throws, the returnedExceptionFilterwill pass through that exception. It only rethrows the original exception ifhandle(Throwable)returns normally (regardless of return value).Typical usage:
ExceptionLogging.log().passing().get(() -> my_throwing_lambda)- Returns:
- pass-through modification of this exception handler
-
runnable
public final Runnable runnable(Runnable runnable)
WrapsRunnablein a try-catch block.If
runnablethrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullrunnableis caught too. Wrapper then completes normally unlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().runnable(() -> my_throwing_lambda)- Parameters:
-
runnable- theRunnableto wrap, usually a lambda - Returns:
-
wrapper that runs
runnablein a try-catch block - See Also:
-
Tutorial,
Exceptions
-
supplier
public final <T> OptionalSupplier<T> supplier(Supplier<T> supplier)
WrapsSupplierin a try-catch block.If
supplierthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullsupplieris caught too. Wrapper then returns emptyOptionalunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().supplier(() -> my_throwing_lambda).orElse(fallback)- Type Parameters:
-
T- seeSupplier - Parameters:
-
supplier- theSupplierto wrap, usually a lambda - Returns:
-
wrapper that runs
supplierin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromIntSupplier
public final OptionalIntSupplier fromIntSupplier(IntSupplier supplier)
WrapsIntSupplierin a try-catch block.If
supplierthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullsupplieris caught too. Wrapper then returns emptyOptionalIntunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromIntSupplier(() -> my_throwing_lambda).orElse(fallback)- Parameters:
-
supplier- theIntSupplierto wrap, usually a lambda - Returns:
-
wrapper that runs
supplierin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromLongSupplier
public final OptionalLongSupplier fromLongSupplier(LongSupplier supplier)
WrapsLongSupplierin a try-catch block.If
supplierthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullsupplieris caught too. Wrapper then returns emptyOptionalLongunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromLongSupplier(() -> my_throwing_lambda).orElse(fallback)- Parameters:
-
supplier- theLongSupplierto wrap, usually a lambda - Returns:
-
wrapper that runs
supplierin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromDoubleSupplier
public final OptionalDoubleSupplier fromDoubleSupplier(DoubleSupplier supplier)
WrapsDoubleSupplierin a try-catch block.If
supplierthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullsupplieris caught too. Wrapper then returns emptyOptionalDoubleunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromDoubleSupplier(() -> my_throwing_lambda).orElse(fallback)- Parameters:
-
supplier- theDoubleSupplierto wrap, usually a lambda - Returns:
-
wrapper that runs
supplierin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromBooleanSupplier
public final OptionalBooleanSupplier fromBooleanSupplier(BooleanSupplier supplier)
WrapsBooleanSupplierin a try-catch block.If
supplierthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullsupplieris caught too. Wrapper then returns emptyOptionalBooleanunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromBooleanSupplier(() -> my_throwing_lambda).orElse(fallback)- Parameters:
-
supplier- theBooleanSupplierto wrap, usually a lambda - Returns:
-
wrapper that runs
supplierin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
consumer
public final <T> Consumer<T> consumer(Consumer<T> consumer)
WrapsConsumerin a try-catch block.If
consumerthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullconsumeris caught too. Wrapper then completes normally unlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().consumer(t -> my_throwing_lambda)- Type Parameters:
-
T- seeConsumer - Parameters:
-
consumer- theConsumerto wrap, usually a lambda - Returns:
-
wrapper that runs
consumerin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromIntConsumer
public final IntConsumer fromIntConsumer(IntConsumer consumer)
WrapsIntConsumerin a try-catch block.If
consumerthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullconsumeris caught too. Wrapper then completes normally unlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromIntConsumer(v -> my_throwing_lambda)- Parameters:
-
consumer- theIntConsumerto wrap, usually a lambda - Returns:
-
wrapper that runs
consumerin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromLongConsumer
public final LongConsumer fromLongConsumer(LongConsumer consumer)
WrapsLongConsumerin a try-catch block.If
consumerthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullconsumeris caught too. Wrapper then completes normally unlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromLongConsumer(v -> my_throwing_lambda)- Parameters:
-
consumer- theLongConsumerto wrap, usually a lambda - Returns:
-
wrapper that runs
consumerin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromDoubleConsumer
public final DoubleConsumer fromDoubleConsumer(DoubleConsumer consumer)
WrapsDoubleConsumerin a try-catch block.If
consumerthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullconsumeris caught too. Wrapper then completes normally unlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromDoubleConsumer(v -> my_throwing_lambda)- Parameters:
-
consumer- theDoubleConsumerto wrap, usually a lambda - Returns:
-
wrapper that runs
consumerin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromBiConsumer
public final <T,U> BiConsumer<T,U> fromBiConsumer(BiConsumer<T,U> consumer)
WrapsBiConsumerin a try-catch block.If
consumerthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullconsumeris caught too. Wrapper then completes normally unlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromBiConsumer((t, u) -> my_throwing_lambda)- Type Parameters:
-
T- seeBiConsumer -
U- seeBiConsumer - Parameters:
-
consumer- theBiConsumerto wrap, usually a lambda - Returns:
-
wrapper that runs
consumerin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromObjIntConsumer
public final <T> ObjIntConsumer<T> fromObjIntConsumer(ObjIntConsumer<T> consumer)
WrapsObjIntConsumerin a try-catch block.If
consumerthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullconsumeris caught too. Wrapper then completes normally unlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromObjIntConsumer((t, v) -> my_throwing_lambda)- Type Parameters:
-
T- seeObjIntConsumer - Parameters:
-
consumer- theObjIntConsumerto wrap, usually a lambda - Returns:
-
wrapper that runs
consumerin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromObjLongConsumer
public final <T> ObjLongConsumer<T> fromObjLongConsumer(ObjLongConsumer<T> consumer)
WrapsObjLongConsumerin a try-catch block.If
consumerthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullconsumeris caught too. Wrapper then completes normally unlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromObjLongConsumer((t, v) -> my_throwing_lambda)- Type Parameters:
-
T- seeObjLongConsumer - Parameters:
-
consumer- theObjLongConsumerto wrap, usually a lambda - Returns:
-
wrapper that runs
consumerin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromObjDoubleConsumer
public final <T> ObjDoubleConsumer<T> fromObjDoubleConsumer(ObjDoubleConsumer<T> consumer)
WrapsObjDoubleConsumerin a try-catch block.If
consumerthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullconsumeris caught too. Wrapper then completes normally unlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromObjDoubleConsumer((t, v) -> my_throwing_lambda)- Type Parameters:
-
T- seeObjDoubleConsumer - Parameters:
-
consumer- theObjDoubleConsumerto wrap, usually a lambda - Returns:
-
wrapper that runs
consumerin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
predicate
public final <T> OptionalPredicate<T> predicate(Predicate<T> predicate)
WrapsPredicatein a try-catch block.If
predicatethrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullpredicateis caught too. Wrapper then returns emptyOptionalBooleanunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().predicate(t -> my_throwing_lambda).orElse(fallback)- Type Parameters:
-
T- seePredicate - Parameters:
-
predicate- thePredicateto wrap, usually a lambda - Returns:
-
wrapper that runs
predicatein a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromIntPredicate
public final OptionalIntPredicate fromIntPredicate(IntPredicate predicate)
WrapsIntPredicatein a try-catch block.If
predicatethrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullpredicateis caught too. Wrapper then returns emptyOptionalBooleanunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromIntPredicate(v -> my_throwing_lambda).orElse(fallback)- Parameters:
-
predicate- theIntPredicateto wrap, usually a lambda - Returns:
-
wrapper that runs
predicatein a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromLongPredicate
public final OptionalLongPredicate fromLongPredicate(LongPredicate predicate)
WrapsLongPredicatein a try-catch block.If
predicatethrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullpredicateis caught too. Wrapper then returns emptyOptionalBooleanunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromLongPredicate(v -> my_throwing_lambda).orElse(fallback)- Parameters:
-
predicate- theLongPredicateto wrap, usually a lambda - Returns:
-
wrapper that runs
predicatein a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromDoublePredicate
public final OptionalDoublePredicate fromDoublePredicate(DoublePredicate predicate)
WrapsDoublePredicatein a try-catch block.If
predicatethrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullpredicateis caught too. Wrapper then returns emptyOptionalBooleanunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromDoublePredicate(v -> my_throwing_lambda).orElse(fallback)- Parameters:
-
predicate- theDoublePredicateto wrap, usually a lambda - Returns:
-
wrapper that runs
predicatein a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromBiPredicate
public final <T,U> OptionalBiPredicate<T,U> fromBiPredicate(BiPredicate<T,U> predicate)
WrapsBiPredicatein a try-catch block.If
predicatethrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullpredicateis caught too. Wrapper then returns emptyOptionalBooleanunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromBiPredicate((t, u) -> my_throwing_lambda).orElse(fallback)- Type Parameters:
-
T- seeBiPredicate -
U- seeBiPredicate - Parameters:
-
predicate- theBiPredicateto wrap, usually a lambda - Returns:
-
wrapper that runs
predicatein a try-catch block - See Also:
-
Tutorial,
Exceptions
-
function
public final <T,R> OptionalFunction<T,R> function(Function<T,R> function)
WrapsFunctionin a try-catch block.If
functionthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullfunctionis caught too. Wrapper then returns emptyOptionalunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().function(t -> my_throwing_lambda).orElse(fallback)- Type Parameters:
-
T- seeFunction -
R- seeFunction - Parameters:
-
function- theFunctionto wrap, usually a lambda - Returns:
-
wrapper that runs
functionin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromToIntFunction
public final <T> OptionalToIntFunction<T> fromToIntFunction(ToIntFunction<T> function)
WrapsToIntFunctionin a try-catch block.If
functionthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullfunctionis caught too. Wrapper then returns emptyOptionalIntunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromToIntFunction(v -> my_throwing_lambda).orElse(fallback)- Type Parameters:
-
T- seeToIntFunction - Parameters:
-
function- theToIntFunctionto wrap, usually a lambda - Returns:
-
wrapper that runs
functionin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromIntFunction
public final <R> OptionalIntFunction<R> fromIntFunction(IntFunction<R> function)
WrapsIntFunctionin a try-catch block.If
functionthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullfunctionis caught too. Wrapper then returns emptyOptionalunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromIntFunction(v -> my_throwing_lambda).orElse(fallback)- Type Parameters:
-
R- seeIntFunction - Parameters:
-
function- theIntFunctionto wrap, usually a lambda - Returns:
-
wrapper that runs
functionin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromIntToLongFunction
public final OptionalIntToLongFunction fromIntToLongFunction(IntToLongFunction function)
WrapsIntToLongFunctionin a try-catch block.If
functionthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullfunctionis caught too. Wrapper then returns emptyOptionalLongunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromIntToLongFunction(v -> my_throwing_lambda).orElse(fallback)- Parameters:
-
function- theIntToLongFunctionto wrap, usually a lambda - Returns:
-
wrapper that runs
functionin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromIntToDoubleFunction
public final OptionalIntToDoubleFunction fromIntToDoubleFunction(IntToDoubleFunction function)
WrapsIntToDoubleFunctionin a try-catch block.If
functionthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullfunctionis caught too. Wrapper then returns emptyOptionalDoubleunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromIntToDoubleFunction(v -> my_throwing_lambda).orElse(fallback)- Parameters:
-
function- theIntToDoubleFunctionto wrap, usually a lambda - Returns:
-
wrapper that runs
functionin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromToLongFunction
public final <T> OptionalToLongFunction<T> fromToLongFunction(ToLongFunction<T> function)
WrapsToLongFunctionin a try-catch block.If
functionthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullfunctionis caught too. Wrapper then returns emptyOptionalLongunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromToLongFunction(v -> my_throwing_lambda).orElse(fallback)- Type Parameters:
-
T- seeToLongFunction - Parameters:
-
function- theToLongFunctionto wrap, usually a lambda - Returns:
-
wrapper that runs
functionin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromLongFunction
public final <R> OptionalLongFunction<R> fromLongFunction(LongFunction<R> function)
WrapsLongFunctionin a try-catch block.If
functionthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullfunctionis caught too. Wrapper then returns emptyOptionalunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromLongFunction(v -> my_throwing_lambda).orElse(fallback)- Type Parameters:
-
R- seeLongFunction - Parameters:
-
function- theLongFunctionto wrap, usually a lambda - Returns:
-
wrapper that runs
functionin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromLongToIntFunction
public final OptionalLongToIntFunction fromLongToIntFunction(LongToIntFunction function)
WrapsLongToIntFunctionin a try-catch block.If
functionthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullfunctionis caught too. Wrapper then returns emptyOptionalIntunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromLongToIntFunction(v -> my_throwing_lambda).orElse(fallback)- Parameters:
-
function- theLongToIntFunctionto wrap, usually a lambda - Returns:
-
wrapper that runs
functionin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromLongToDoubleFunction
public final OptionalLongToDoubleFunction fromLongToDoubleFunction(LongToDoubleFunction function)
WrapsLongToDoubleFunctionin a try-catch block.If
functionthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullfunctionis caught too. Wrapper then returns emptyOptionalDoubleunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromLongToDoubleFunction(v -> my_throwing_lambda).orElse(fallback)- Parameters:
-
function- theLongToDoubleFunctionto wrap, usually a lambda - Returns:
-
wrapper that runs
functionin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromToDoubleFunction
public final <T> OptionalToDoubleFunction<T> fromToDoubleFunction(ToDoubleFunction<T> function)
WrapsToDoubleFunctionin a try-catch block.If
functionthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullfunctionis caught too. Wrapper then returns emptyOptionalDoubleunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromToDoubleFunction(v -> my_throwing_lambda).orElse(fallback)- Type Parameters:
-
T- seeToDoubleFunction - Parameters:
-
function- theToDoubleFunctionto wrap, usually a lambda - Returns:
-
wrapper that runs
functionin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromDoubleFunction
public final <R> OptionalDoubleFunction<R> fromDoubleFunction(DoubleFunction<R> function)
WrapsDoubleFunctionin a try-catch block.If
functionthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullfunctionis caught too. Wrapper then returns emptyOptionalunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromDoubleFunction(v -> my_throwing_lambda).orElse(fallback)- Type Parameters:
-
R- seeDoubleFunction - Parameters:
-
function- theDoubleFunctionto wrap, usually a lambda - Returns:
-
wrapper that runs
functionin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromDoubleToIntFunction
public final OptionalDoubleToIntFunction fromDoubleToIntFunction(DoubleToIntFunction function)
WrapsDoubleToIntFunctionin a try-catch block.If
functionthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullfunctionis caught too. Wrapper then returns emptyOptionalIntunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromDoubleToIntFunction(v -> my_throwing_lambda).orElse(fallback)- Parameters:
-
function- theDoubleToIntFunctionto wrap, usually a lambda - Returns:
-
wrapper that runs
functionin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromDoubleToLongFunction
public final OptionalDoubleToLongFunction fromDoubleToLongFunction(DoubleToLongFunction function)
WrapsDoubleToLongFunctionin a try-catch block.If
functionthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullfunctionis caught too. Wrapper then returns emptyOptionalLongunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromDoubleToLongFunction(v -> my_throwing_lambda).orElse(fallback)- Parameters:
-
function- theDoubleToLongFunctionto wrap, usually a lambda - Returns:
-
wrapper that runs
functionin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromUnaryOperator
public final <T> OptionalUnaryOperator<T> fromUnaryOperator(UnaryOperator<T> operator)
WrapsUnaryOperatorin a try-catch block.If
operatorthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnulloperatoris caught too. Wrapper then returns emptyOptionalunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromUnaryOperator(o -> my_throwing_lambda).orElse(fallback)- Type Parameters:
-
T- seeUnaryOperator - Parameters:
-
operator- theUnaryOperatorto wrap, usually a lambda - Returns:
-
wrapper that runs
operatorin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromIntUnaryOperator
public final OptionalIntUnaryOperator fromIntUnaryOperator(IntUnaryOperator operator)
WrapsIntUnaryOperatorin a try-catch block.If
operatorthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnulloperatoris caught too. Wrapper then returns emptyOptionalIntunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromIntUnaryOperator(o -> my_throwing_lambda).orElse(fallback)- Parameters:
-
operator- theIntUnaryOperatorto wrap, usually a lambda - Returns:
-
wrapper that runs
operatorin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromLongUnaryOperator
public final OptionalLongUnaryOperator fromLongUnaryOperator(LongUnaryOperator operator)
WrapsLongUnaryOperatorin a try-catch block.If
operatorthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnulloperatoris caught too. Wrapper then returns emptyOptionalLongunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromLongUnaryOperator(o -> my_throwing_lambda).orElse(fallback)- Parameters:
-
operator- theLongUnaryOperatorto wrap, usually a lambda - Returns:
-
wrapper that runs
operatorin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromDoubleUnaryOperator
public final OptionalDoubleUnaryOperator fromDoubleUnaryOperator(DoubleUnaryOperator operator)
WrapsDoubleUnaryOperatorin a try-catch block.If
operatorthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnulloperatoris caught too. Wrapper then returns emptyOptionalDoubleunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromDoubleUnaryOperator(o -> my_throwing_lambda).orElse(fallback)- Parameters:
-
operator- theDoubleUnaryOperatorto wrap, usually a lambda - Returns:
-
wrapper that runs
operatorin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromBiFunction
public final <T,U,R> OptionalBiFunction<T,U,R> fromBiFunction(BiFunction<T,U,R> function)
WrapsBiFunctionin a try-catch block.If
functionthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullfunctionis caught too. Wrapper then returns emptyOptionalunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromBiFunction((t, u) -> my_throwing_lambda).orElse(fallback)- Type Parameters:
-
T- seeBiFunction -
U- seeBiFunction -
R- seeBiFunction - Parameters:
-
function- theBiFunctionto wrap, usually a lambda - Returns:
-
wrapper that runs
functionin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromToIntBiFunction
public final <T,U> OptionalToIntBiFunction<T,U> fromToIntBiFunction(ToIntBiFunction<T,U> function)
WrapsToIntBiFunctionin a try-catch block.If
functionthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullfunctionis caught too. Wrapper then returns emptyOptionalIntunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromToIntBiFunction((t, u) -> my_throwing_lambda).orElse(fallback)- Type Parameters:
-
T- seeToIntBiFunction -
U- seeToIntBiFunction - Parameters:
-
function- theToIntBiFunctionto wrap, usually a lambda - Returns:
-
wrapper that runs
functionin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromToLongBiFunction
public final <T,U> OptionalToLongBiFunction<T,U> fromToLongBiFunction(ToLongBiFunction<T,U> function)
WrapsToLongBiFunctionin a try-catch block.If
functionthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullfunctionis caught too. Wrapper then returns emptyOptionalLongunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromToLongBiFunction((t, u) -> my_throwing_lambda).orElse(fallback)- Type Parameters:
-
T- seeToLongBiFunction -
U- seeToLongBiFunction - Parameters:
-
function- theToLongBiFunctionto wrap, usually a lambda - Returns:
-
wrapper that runs
functionin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromToDoubleBiFunction
public final <T,U> OptionalToDoubleBiFunction<T,U> fromToDoubleBiFunction(ToDoubleBiFunction<T,U> function)
WrapsToDoubleBiFunctionin a try-catch block.If
functionthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullfunctionis caught too. Wrapper then returns emptyOptionalDoubleunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromToDoubleBiFunction((t, u) -> my_throwing_lambda).orElse(fallback)- Type Parameters:
-
T- seeToDoubleBiFunction -
U- seeToDoubleBiFunction - Parameters:
-
function- theToDoubleBiFunctionto wrap, usually a lambda - Returns:
-
wrapper that runs
functionin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromBinaryOperator
public final <T> OptionalBinaryOperator<T> fromBinaryOperator(BinaryOperator<T> operator)
WrapsBinaryOperatorin a try-catch block.If
operatorthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnulloperatoris caught too. Wrapper then returns emptyOptionalunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromBinaryOperator((l, r) -> my_throwing_lambda).orElse(fallback)- Type Parameters:
-
T- seeBinaryOperator - Parameters:
-
operator- theBinaryOperatorto wrap, usually a lambda - Returns:
-
wrapper that runs
operatorin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromIntBinaryOperator
public final OptionalIntBinaryOperator fromIntBinaryOperator(IntBinaryOperator operator)
WrapsIntBinaryOperatorin a try-catch block.If
operatorthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnulloperatoris caught too. Wrapper then returns emptyOptionalIntunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromIntBinaryOperator((l, r) -> my_throwing_lambda).orElse(fallback)- Parameters:
-
operator- theIntBinaryOperatorto wrap, usually a lambda - Returns:
-
wrapper that runs
operatorin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromLongBinaryOperator
public final OptionalLongBinaryOperator fromLongBinaryOperator(LongBinaryOperator operator)
WrapsLongBinaryOperatorin a try-catch block.If
operatorthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnulloperatoris caught too. Wrapper then returns emptyOptionalLongunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromLongBinaryOperator((l, r) -> my_throwing_lambda).orElse(fallback)- Parameters:
-
operator- theLongBinaryOperatorto wrap, usually a lambda - Returns:
-
wrapper that runs
operatorin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
fromDoubleBinaryOperator
public final OptionalDoubleBinaryOperator fromDoubleBinaryOperator(DoubleBinaryOperator operator)
WrapsDoubleBinaryOperatorin a try-catch block.If
operatorthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnulloperatoris caught too. Wrapper then returns emptyOptionalDoubleunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().fromDoubleBinaryOperator((l, r) -> my_throwing_lambda).orElse(fallback)- Parameters:
-
operator- theDoubleBinaryOperatorto wrap, usually a lambda - Returns:
-
wrapper that runs
operatorin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
comparator
public final <T> OptionalComparator<T> comparator(Comparator<T> comparator)
WrapsComparatorin a try-catch block.If
comparatorthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullcomparatoris caught too. Wrapper then returns emptyOptionalIntunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().comparator((l, r) -> my_throwing_lambda).orElse(fallback)- Type Parameters:
-
T- seeComparator - Parameters:
-
comparator- theComparatorto wrap, usually a lambda - Returns:
-
wrapper that runs
comparatorin a try-catch block - See Also:
-
Tutorial,
Exceptions
-
closeable
public final CloseableScope closeable(CloseableScope closeable)
WrapsCloseableScopein a try-catch block.If
closeablethrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullcloseableis caught too. Wrapper then completes normally unlesshandle(Throwable)requests a rethrow.Typical usage:
try (var scope = Exceptions.silence().closeable(openSomething()))- Parameters:
-
closeable- theCloseableScopeto wrap - Returns:
-
wrapper that runs
closeablein a try-catch block - See Also:
-
Tutorial,
Exceptions
-
run
public final void run(Runnable runnable)
RunsRunnablein a try-catch block.If
runnablethrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullrunnableis caught too. This method then completes normally unlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().run(() -> my_throwing_lambda)- Parameters:
-
runnable- theRunnableto run, usually a lambda - See Also:
-
Tutorial,
Exceptions
-
get
public final <T> Optional<T> get(Supplier<T> supplier)
RunsSupplierin a try-catch block.If
supplierthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullsupplieris caught too. This method then returns emptyOptionalunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().get(() -> my_throwing_lambda)
-
getAsInt
public final OptionalInt getAsInt(IntSupplier supplier)
RunsIntSupplierin a try-catch block.If
supplierthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullsupplieris caught too. This method then returns emptyOptionalIntunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().getAsInt(() -> my_throwing_lambda)- Parameters:
-
supplier- theIntSupplierto run, usually a lambda - Returns:
-
an
OptionalIntcarryingsupplierresult or an emptyOptionalIntif exception was caught - See Also:
-
Tutorial,
Exceptions
-
getAsLong
public final OptionalLong getAsLong(LongSupplier supplier)
RunsLongSupplierin a try-catch block.If
supplierthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullsupplieris caught too. This method then returns emptyOptionalLongunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().getAsLong(() -> my_throwing_lambda)- Parameters:
-
supplier- theLongSupplierto run, usually a lambda - Returns:
-
an
OptionalLongcarryingsupplierresult or an emptyOptionalLongif exception was caught - See Also:
-
Tutorial,
Exceptions
-
getAsDouble
public final OptionalDouble getAsDouble(DoubleSupplier supplier)
RunsDoubleSupplierin a try-catch block.If
supplierthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullsupplieris caught too. This method then returns emptyOptionalDoubleunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().getAsDouble(() -> my_throwing_lambda)- Parameters:
-
supplier- theDoubleSupplierto run, usually a lambda - Returns:
-
an
OptionalDoublecarryingsupplierresult or an emptyOptionalDoubleif exception was caught - See Also:
-
Tutorial,
Exceptions
-
getAsBoolean
public final OptionalBoolean getAsBoolean(BooleanSupplier supplier)
RunsBooleanSupplierin a try-catch block.If
supplierthrows, the exception is caught and passed tohandle(Throwable), which applies exception handling policy (silence, propagate, log, custom).NullPointerExceptionfromnullsupplieris caught too. This method then returns emptyOptionalBooleanunlesshandle(Throwable)requests a rethrow.Typical usage:
Exceptions.silence().getAsBoolean(() -> my_throwing_lambda)- Parameters:
-
supplier- theBooleanSupplierto run, usually a lambda - Returns:
-
an
OptionalBooleancarryingsupplierresult or an emptyOptionalBooleanif exception was caught - See Also:
-
Tutorial,
Exceptions
-
-