- 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).NullPointerException
fromnull
functional 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 followfromX
naming pattern, for examplefromUnaryOperator(UnaryOperator)
. Parameterless functional interfaces can be called directly by methodsrun(Runnable)
,get(Supplier)
, and the variousgetAsX
variants.All non-void wrappers conform to some
OptionalX
functional interface, for exampleOptionalSupplier
, that is identical to its non-optional variant from JDK except it returnsOptional
instead of raw value. ThisOptional
is empty in case of exception. Callers can useOptional.orElse(Object)
andOptional.orElseGet(Supplier)
and their equivalents onOptionalX
interfaces to provide fallback values.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ExceptionHandler()
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 onExceptions
class. All other methods of theExceptionHandler
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
- ifexception
isnull
- 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 returnExceptionFilter
that performs the same action but additionally rethrows the exception.Reusable exception handlers can be defined once as
ExceptionHandler
instances and then transformed intoExceptionFilter
by this method when needed.If method
handle(Throwable)
throws, the returnedExceptionFilter
will 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)
WrapsRunnable
in a try-catch block.If
runnable
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
runnable
is caught too. Wrapper then completes normally unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().runnable(() -> my_throwing_lambda)
- Parameters:
-
runnable
- theRunnable
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)
WrapsSupplier
in a try-catch block.If
supplier
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
supplier
is caught too. Wrapper then returns emptyOptional
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().supplier(() -> my_throwing_lambda).orElse(fallback)
- Type Parameters:
-
T
- seeSupplier
- Parameters:
-
supplier
- theSupplier
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)
WrapsIntSupplier
in a try-catch block.If
supplier
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
supplier
is caught too. Wrapper then returns emptyOptionalInt
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromIntSupplier(() -> my_throwing_lambda).orElse(fallback)
- Parameters:
-
supplier
- theIntSupplier
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)
WrapsLongSupplier
in a try-catch block.If
supplier
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
supplier
is caught too. Wrapper then returns emptyOptionalLong
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromLongSupplier(() -> my_throwing_lambda).orElse(fallback)
- Parameters:
-
supplier
- theLongSupplier
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)
WrapsDoubleSupplier
in a try-catch block.If
supplier
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
supplier
is caught too. Wrapper then returns emptyOptionalDouble
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromDoubleSupplier(() -> my_throwing_lambda).orElse(fallback)
- Parameters:
-
supplier
- theDoubleSupplier
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)
WrapsBooleanSupplier
in a try-catch block.If
supplier
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
supplier
is caught too. Wrapper then returns emptyOptionalBoolean
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromBooleanSupplier(() -> my_throwing_lambda).orElse(fallback)
- Parameters:
-
supplier
- theBooleanSupplier
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)
WrapsConsumer
in a try-catch block.If
consumer
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
consumer
is 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
- theConsumer
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)
WrapsIntConsumer
in a try-catch block.If
consumer
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
consumer
is caught too. Wrapper then completes normally unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromIntConsumer(v -> my_throwing_lambda)
- Parameters:
-
consumer
- theIntConsumer
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)
WrapsLongConsumer
in a try-catch block.If
consumer
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
consumer
is caught too. Wrapper then completes normally unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromLongConsumer(v -> my_throwing_lambda)
- Parameters:
-
consumer
- theLongConsumer
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)
WrapsDoubleConsumer
in a try-catch block.If
consumer
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
consumer
is caught too. Wrapper then completes normally unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromDoubleConsumer(v -> my_throwing_lambda)
- Parameters:
-
consumer
- theDoubleConsumer
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)
WrapsBiConsumer
in a try-catch block.If
consumer
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
consumer
is 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
- theBiConsumer
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)
WrapsObjIntConsumer
in a try-catch block.If
consumer
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
consumer
is 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
- theObjIntConsumer
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)
WrapsObjLongConsumer
in a try-catch block.If
consumer
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
consumer
is 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
- theObjLongConsumer
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)
WrapsObjDoubleConsumer
in a try-catch block.If
consumer
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
consumer
is 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
- theObjDoubleConsumer
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)
WrapsPredicate
in a try-catch block.If
predicate
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
predicate
is caught too. Wrapper then returns emptyOptionalBoolean
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().predicate(t -> my_throwing_lambda).orElse(fallback)
- Type Parameters:
-
T
- seePredicate
- Parameters:
-
predicate
- thePredicate
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)
WrapsIntPredicate
in a try-catch block.If
predicate
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
predicate
is caught too. Wrapper then returns emptyOptionalBoolean
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromIntPredicate(v -> my_throwing_lambda).orElse(fallback)
- Parameters:
-
predicate
- theIntPredicate
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)
WrapsLongPredicate
in a try-catch block.If
predicate
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
predicate
is caught too. Wrapper then returns emptyOptionalBoolean
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromLongPredicate(v -> my_throwing_lambda).orElse(fallback)
- Parameters:
-
predicate
- theLongPredicate
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)
WrapsDoublePredicate
in a try-catch block.If
predicate
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
predicate
is caught too. Wrapper then returns emptyOptionalBoolean
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromDoublePredicate(v -> my_throwing_lambda).orElse(fallback)
- Parameters:
-
predicate
- theDoublePredicate
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)
WrapsBiPredicate
in a try-catch block.If
predicate
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
predicate
is caught too. Wrapper then returns emptyOptionalBoolean
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromBiPredicate((t, u) -> my_throwing_lambda).orElse(fallback)
- Type Parameters:
-
T
- seeBiPredicate
-
U
- seeBiPredicate
- Parameters:
-
predicate
- theBiPredicate
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)
WrapsFunction
in a try-catch block.If
function
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
function
is caught too. Wrapper then returns emptyOptional
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().function(t -> my_throwing_lambda).orElse(fallback)
- Type Parameters:
-
T
- seeFunction
-
R
- seeFunction
- Parameters:
-
function
- theFunction
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)
WrapsToIntFunction
in a try-catch block.If
function
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
function
is caught too. Wrapper then returns emptyOptionalInt
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromToIntFunction(v -> my_throwing_lambda).orElse(fallback)
- Type Parameters:
-
T
- seeToIntFunction
- Parameters:
-
function
- theToIntFunction
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)
WrapsIntFunction
in a try-catch block.If
function
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
function
is caught too. Wrapper then returns emptyOptional
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromIntFunction(v -> my_throwing_lambda).orElse(fallback)
- Type Parameters:
-
R
- seeIntFunction
- Parameters:
-
function
- theIntFunction
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)
WrapsIntToLongFunction
in a try-catch block.If
function
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
function
is caught too. Wrapper then returns emptyOptionalLong
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromIntToLongFunction(v -> my_throwing_lambda).orElse(fallback)
- Parameters:
-
function
- theIntToLongFunction
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)
WrapsIntToDoubleFunction
in a try-catch block.If
function
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
function
is caught too. Wrapper then returns emptyOptionalDouble
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromIntToDoubleFunction(v -> my_throwing_lambda).orElse(fallback)
- Parameters:
-
function
- theIntToDoubleFunction
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)
WrapsToLongFunction
in a try-catch block.If
function
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
function
is caught too. Wrapper then returns emptyOptionalLong
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromToLongFunction(v -> my_throwing_lambda).orElse(fallback)
- Type Parameters:
-
T
- seeToLongFunction
- Parameters:
-
function
- theToLongFunction
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)
WrapsLongFunction
in a try-catch block.If
function
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
function
is caught too. Wrapper then returns emptyOptional
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromLongFunction(v -> my_throwing_lambda).orElse(fallback)
- Type Parameters:
-
R
- seeLongFunction
- Parameters:
-
function
- theLongFunction
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)
WrapsLongToIntFunction
in a try-catch block.If
function
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
function
is caught too. Wrapper then returns emptyOptionalInt
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromLongToIntFunction(v -> my_throwing_lambda).orElse(fallback)
- Parameters:
-
function
- theLongToIntFunction
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)
WrapsLongToDoubleFunction
in a try-catch block.If
function
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
function
is caught too. Wrapper then returns emptyOptionalDouble
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromLongToDoubleFunction(v -> my_throwing_lambda).orElse(fallback)
- Parameters:
-
function
- theLongToDoubleFunction
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)
WrapsToDoubleFunction
in a try-catch block.If
function
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
function
is caught too. Wrapper then returns emptyOptionalDouble
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromToDoubleFunction(v -> my_throwing_lambda).orElse(fallback)
- Type Parameters:
-
T
- seeToDoubleFunction
- Parameters:
-
function
- theToDoubleFunction
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)
WrapsDoubleFunction
in a try-catch block.If
function
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
function
is caught too. Wrapper then returns emptyOptional
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromDoubleFunction(v -> my_throwing_lambda).orElse(fallback)
- Type Parameters:
-
R
- seeDoubleFunction
- Parameters:
-
function
- theDoubleFunction
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)
WrapsDoubleToIntFunction
in a try-catch block.If
function
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
function
is caught too. Wrapper then returns emptyOptionalInt
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromDoubleToIntFunction(v -> my_throwing_lambda).orElse(fallback)
- Parameters:
-
function
- theDoubleToIntFunction
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)
WrapsDoubleToLongFunction
in a try-catch block.If
function
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
function
is caught too. Wrapper then returns emptyOptionalLong
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromDoubleToLongFunction(v -> my_throwing_lambda).orElse(fallback)
- Parameters:
-
function
- theDoubleToLongFunction
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)
WrapsUnaryOperator
in a try-catch block.If
operator
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
operator
is caught too. Wrapper then returns emptyOptional
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromUnaryOperator(o -> my_throwing_lambda).orElse(fallback)
- Type Parameters:
-
T
- seeUnaryOperator
- Parameters:
-
operator
- theUnaryOperator
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)
WrapsIntUnaryOperator
in a try-catch block.If
operator
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
operator
is caught too. Wrapper then returns emptyOptionalInt
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromIntUnaryOperator(o -> my_throwing_lambda).orElse(fallback)
- Parameters:
-
operator
- theIntUnaryOperator
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)
WrapsLongUnaryOperator
in a try-catch block.If
operator
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
operator
is caught too. Wrapper then returns emptyOptionalLong
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromLongUnaryOperator(o -> my_throwing_lambda).orElse(fallback)
- Parameters:
-
operator
- theLongUnaryOperator
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)
WrapsDoubleUnaryOperator
in a try-catch block.If
operator
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
operator
is caught too. Wrapper then returns emptyOptionalDouble
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromDoubleUnaryOperator(o -> my_throwing_lambda).orElse(fallback)
- Parameters:
-
operator
- theDoubleUnaryOperator
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)
WrapsBiFunction
in a try-catch block.If
function
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
function
is caught too. Wrapper then returns emptyOptional
unlesshandle(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
- theBiFunction
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)
WrapsToIntBiFunction
in a try-catch block.If
function
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
function
is caught too. Wrapper then returns emptyOptionalInt
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromToIntBiFunction((t, u) -> my_throwing_lambda).orElse(fallback)
- Type Parameters:
-
T
- seeToIntBiFunction
-
U
- seeToIntBiFunction
- Parameters:
-
function
- theToIntBiFunction
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)
WrapsToLongBiFunction
in a try-catch block.If
function
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
function
is caught too. Wrapper then returns emptyOptionalLong
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromToLongBiFunction((t, u) -> my_throwing_lambda).orElse(fallback)
- Type Parameters:
-
T
- seeToLongBiFunction
-
U
- seeToLongBiFunction
- Parameters:
-
function
- theToLongBiFunction
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)
WrapsToDoubleBiFunction
in a try-catch block.If
function
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
function
is caught too. Wrapper then returns emptyOptionalDouble
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromToDoubleBiFunction((t, u) -> my_throwing_lambda).orElse(fallback)
- Type Parameters:
-
T
- seeToDoubleBiFunction
-
U
- seeToDoubleBiFunction
- Parameters:
-
function
- theToDoubleBiFunction
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)
WrapsBinaryOperator
in a try-catch block.If
operator
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
operator
is caught too. Wrapper then returns emptyOptional
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromBinaryOperator((l, r) -> my_throwing_lambda).orElse(fallback)
- Type Parameters:
-
T
- seeBinaryOperator
- Parameters:
-
operator
- theBinaryOperator
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)
WrapsIntBinaryOperator
in a try-catch block.If
operator
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
operator
is caught too. Wrapper then returns emptyOptionalInt
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromIntBinaryOperator((l, r) -> my_throwing_lambda).orElse(fallback)
- Parameters:
-
operator
- theIntBinaryOperator
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)
WrapsLongBinaryOperator
in a try-catch block.If
operator
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
operator
is caught too. Wrapper then returns emptyOptionalLong
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromLongBinaryOperator((l, r) -> my_throwing_lambda).orElse(fallback)
- Parameters:
-
operator
- theLongBinaryOperator
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)
WrapsDoubleBinaryOperator
in a try-catch block.If
operator
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
operator
is caught too. Wrapper then returns emptyOptionalDouble
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().fromDoubleBinaryOperator((l, r) -> my_throwing_lambda).orElse(fallback)
- Parameters:
-
operator
- theDoubleBinaryOperator
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)
WrapsComparator
in a try-catch block.If
comparator
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
comparator
is caught too. Wrapper then returns emptyOptionalInt
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().comparator((l, r) -> my_throwing_lambda).orElse(fallback)
- Type Parameters:
-
T
- seeComparator
- Parameters:
-
comparator
- theComparator
to wrap, usually a lambda - Returns:
-
wrapper that runs
comparator
in a try-catch block - See Also:
-
Tutorial,
Exceptions
-
closeable
public final CloseableScope closeable(CloseableScope closeable)
WrapsCloseableScope
in a try-catch block.If
closeable
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
closeable
is caught too. Wrapper then completes normally unlesshandle(Throwable)
requests a rethrow.Typical usage:
try (var scope = Exceptions.silence().closeable(openSomething()))
- Parameters:
-
closeable
- theCloseableScope
to wrap - Returns:
-
wrapper that runs
closeable
in a try-catch block - See Also:
-
Tutorial,
Exceptions
-
run
public final void run(Runnable runnable)
RunsRunnable
in a try-catch block.If
runnable
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
runnable
is caught too. This method then completes normally unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().run(() -> my_throwing_lambda)
- Parameters:
-
runnable
- theRunnable
to run, usually a lambda - See Also:
-
Tutorial,
Exceptions
-
get
public final <T> Optional<T> get(Supplier<T> supplier)
RunsSupplier
in a try-catch block.If
supplier
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
supplier
is caught too. This method then returns emptyOptional
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().get(() -> my_throwing_lambda)
-
getAsInt
public final OptionalInt getAsInt(IntSupplier supplier)
RunsIntSupplier
in a try-catch block.If
supplier
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
supplier
is caught too. This method then returns emptyOptionalInt
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().getAsInt(() -> my_throwing_lambda)
- Parameters:
-
supplier
- theIntSupplier
to run, usually a lambda - Returns:
-
an
OptionalInt
carryingsupplier
result or an emptyOptionalInt
if exception was caught - See Also:
-
Tutorial,
Exceptions
-
getAsLong
public final OptionalLong getAsLong(LongSupplier supplier)
RunsLongSupplier
in a try-catch block.If
supplier
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
supplier
is caught too. This method then returns emptyOptionalLong
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().getAsLong(() -> my_throwing_lambda)
- Parameters:
-
supplier
- theLongSupplier
to run, usually a lambda - Returns:
-
an
OptionalLong
carryingsupplier
result or an emptyOptionalLong
if exception was caught - See Also:
-
Tutorial,
Exceptions
-
getAsDouble
public final OptionalDouble getAsDouble(DoubleSupplier supplier)
RunsDoubleSupplier
in a try-catch block.If
supplier
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
supplier
is caught too. This method then returns emptyOptionalDouble
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().getAsDouble(() -> my_throwing_lambda)
- Parameters:
-
supplier
- theDoubleSupplier
to run, usually a lambda - Returns:
-
an
OptionalDouble
carryingsupplier
result or an emptyOptionalDouble
if exception was caught - See Also:
-
Tutorial,
Exceptions
-
getAsBoolean
public final OptionalBoolean getAsBoolean(BooleanSupplier supplier)
RunsBooleanSupplier
in a try-catch block.If
supplier
throws, the exception is caught and passed tohandle(Throwable)
, which applies exception handling policy (silence, propagate, log, custom).NullPointerException
fromnull
supplier
is caught too. This method then returns emptyOptionalBoolean
unlesshandle(Throwable)
requests a rethrow.Typical usage:
Exceptions.silence().getAsBoolean(() -> my_throwing_lambda)
- Parameters:
-
supplier
- theBooleanSupplier
to run, usually a lambda - Returns:
-
an
OptionalBoolean
carryingsupplier
result or an emptyOptionalBoolean
if exception was caught - See Also:
-
Tutorial,
Exceptions
-
-