public abstract class CheckedExceptionHandler extends Object
catch
block that catches checked exception and throws an unchecked one. Method handle(Exception)
defines downgrading mechanism, typically by wrapping the checked exception in an unchecked one, but there are special cases like Exceptions.sneak()
, which downgrade only method signature without altering the exception itself. Methods of this class apply the exception policy to functional interfaces (usually lambdas) by wrapping them in a try-catch block. See noexception tutorial.
Typical usage: Exceptions.sneak().get(() -> my_throwing_lambda)
CheckedExceptionHandler
does not stop propagation of any exceptions (checked or unchecked). ExceptionHandler
is used for that purpose. The two classes can be used together by first downgrading checked exceptions with CheckedExceptionHandler
and then applying exception handling policy with ExceptionHandler
.
Combined usage: Exceptions.log().get(Exceptions.sneak().supplier(() -> my_throwing_lambda)).orElse(fallback)
All wrapping methods surround the functional interface with a try-catch block. Only checked exceptions are handled. Unchecked exceptions are propagated to caller. If the functional interface throws checked exception, the exception is caught and passed to handle(Exception)
, which converts it to an unchecked exception, which is then thrown.
Wrapping methods for all standard functional interfaces are provided. Simple interfaces have short method names, like runnable(ThrowingRunnable)
or supplier(ThrowingSupplier)
. Interfaces with longer names have methods that follow fromX
naming pattern, for example fromUnaryOperator(ThrowingUnaryOperator)
. Parameterless functional interfaces can be called directly by methods run(ThrowingRunnable)
, get(ThrowingSupplier)
, and the various getAsX
variants. All methods take throwing versions of standard functional interfaces, for example ThrowingRunnable
or ThrowingSupplier
.
handle(Exception)
, Exceptions
, ExceptionHandler
, ExceptionFilter
Modifier | Constructor and Description |
---|---|
protected |
CheckedExceptionHandler()
Initializes new CheckedExceptionHandler .
|
Modifier and Type | Method and Description |
---|---|
CloseableScope |
closeable(AutoCloseable closeable)
Removes checked exceptions from method signature of AutoCloseable .
|
<T> Comparator<T> |
comparator(ThrowingComparator<T> comparator)
Removes checked exceptions from method signature of ThrowingComparator .
|
<T> Consumer<T> |
consumer(ThrowingConsumer<T> consumer)
Removes checked exceptions from method signature of ThrowingConsumer .
|
<T,U> BiConsumer<T,U> |
fromBiConsumer(ThrowingBiConsumer<T,U> consumer)
Removes checked exceptions from method signature of ThrowingBiConsumer .
|
<T,U,R> BiFunction<T,U,R> |
fromBiFunction(ThrowingBiFunction<T,U,R> function)
Removes checked exceptions from method signature of ThrowingBiFunction .
|
<T> BinaryOperator<T> |
fromBinaryOperator(ThrowingBinaryOperator<T> operator)
Removes checked exceptions from method signature of ThrowingBinaryOperator .
|
<T,U> BiPredicate<T,U> |
fromBiPredicate(ThrowingBiPredicate<T,U> predicate)
Removes checked exceptions from method signature of ThrowingBiPredicate .
|
BooleanSupplier |
fromBooleanSupplier(ThrowingBooleanSupplier supplier)
Removes checked exceptions from method signature of ThrowingBooleanSupplier .
|
DoubleBinaryOperator |
fromDoubleBinaryOperator(ThrowingDoubleBinaryOperator operator)
Removes checked exceptions from method signature of ThrowingDoubleBinaryOperator .
|
DoubleConsumer |
fromDoubleConsumer(ThrowingDoubleConsumer consumer)
Removes checked exceptions from method signature of ThrowingDoubleConsumer .
|
<R> DoubleFunction<R> |
fromDoubleFunction(ThrowingDoubleFunction<R> function)
Removes checked exceptions from method signature of ThrowingDoubleFunction .
|
DoublePredicate |
fromDoublePredicate(ThrowingDoublePredicate predicate)
Removes checked exceptions from method signature of ThrowingDoublePredicate .
|
DoubleSupplier |
fromDoubleSupplier(ThrowingDoubleSupplier supplier)
Removes checked exceptions from method signature of ThrowingDoubleSupplier .
|
DoubleToIntFunction |
fromDoubleToIntFunction(ThrowingDoubleToIntFunction function)
Removes checked exceptions from method signature of ThrowingDoubleToIntFunction .
|
DoubleToLongFunction |
fromDoubleToLongFunction(ThrowingDoubleToLongFunction function)
Removes checked exceptions from method signature of ThrowingDoubleToLongFunction .
|
DoubleUnaryOperator |
fromDoubleUnaryOperator(ThrowingDoubleUnaryOperator operator)
Removes checked exceptions from method signature of ThrowingDoubleUnaryOperator .
|
IntBinaryOperator |
fromIntBinaryOperator(ThrowingIntBinaryOperator operator)
Removes checked exceptions from method signature of ThrowingIntBinaryOperator .
|
IntConsumer |
fromIntConsumer(ThrowingIntConsumer consumer)
Removes checked exceptions from method signature of ThrowingIntConsumer .
|
<R> IntFunction<R> |
fromIntFunction(ThrowingIntFunction<R> function)
Removes checked exceptions from method signature of ThrowingIntFunction .
|
IntPredicate |
fromIntPredicate(ThrowingIntPredicate predicate)
Removes checked exceptions from method signature of ThrowingIntPredicate .
|
IntSupplier |
fromIntSupplier(ThrowingIntSupplier supplier)
Removes checked exceptions from method signature of ThrowingIntSupplier .
|
IntToDoubleFunction |
fromIntToDoubleFunction(ThrowingIntToDoubleFunction function)
Removes checked exceptions from method signature of ThrowingIntToDoubleFunction .
|
IntToLongFunction |
fromIntToLongFunction(ThrowingIntToLongFunction function)
Removes checked exceptions from method signature of ThrowingIntToLongFunction .
|
IntUnaryOperator |
fromIntUnaryOperator(ThrowingIntUnaryOperator operator)
Removes checked exceptions from method signature of ThrowingIntUnaryOperator .
|
LongBinaryOperator |
fromLongBinaryOperator(ThrowingLongBinaryOperator operator)
Removes checked exceptions from method signature of ThrowingLongBinaryOperator .
|
LongConsumer |
fromLongConsumer(ThrowingLongConsumer consumer)
Removes checked exceptions from method signature of ThrowingLongConsumer .
|
<R> LongFunction<R> |
fromLongFunction(ThrowingLongFunction<R> function)
Removes checked exceptions from method signature of ThrowingLongFunction .
|
LongPredicate |
fromLongPredicate(ThrowingLongPredicate predicate)
Removes checked exceptions from method signature of ThrowingLongPredicate .
|
LongSupplier |
fromLongSupplier(ThrowingLongSupplier supplier)
Removes checked exceptions from method signature of ThrowingLongSupplier .
|
LongToDoubleFunction |
fromLongToDoubleFunction(ThrowingLongToDoubleFunction function)
Removes checked exceptions from method signature of ThrowingLongToDoubleFunction .
|
LongToIntFunction |
fromLongToIntFunction(ThrowingLongToIntFunction function)
Removes checked exceptions from method signature of ThrowingLongToIntFunction .
|
LongUnaryOperator |
fromLongUnaryOperator(ThrowingLongUnaryOperator operator)
Removes checked exceptions from method signature of ThrowingLongUnaryOperator .
|
<T> ObjDoubleConsumer<T> |
fromObjDoubleConsumer(ThrowingObjDoubleConsumer<T> consumer)
Removes checked exceptions from method signature of ThrowingObjDoubleConsumer .
|
<T> ObjIntConsumer<T> |
fromObjIntConsumer(ThrowingObjIntConsumer<T> consumer)
Removes checked exceptions from method signature of ThrowingObjIntConsumer .
|
<T> ObjLongConsumer<T> |
fromObjLongConsumer(ThrowingObjLongConsumer<T> consumer)
Removes checked exceptions from method signature of ThrowingObjLongConsumer .
|
<T,U> ToDoubleBiFunction<T,U> |
fromToDoubleBiFunction(ThrowingToDoubleBiFunction<T,U> function)
Removes checked exceptions from method signature of ThrowingToDoubleBiFunction .
|
<T> ToDoubleFunction<T> |
fromToDoubleFunction(ThrowingToDoubleFunction<T> function)
Removes checked exceptions from method signature of ThrowingToDoubleFunction .
|
<T,U> ToIntBiFunction<T,U> |
fromToIntBiFunction(ThrowingToIntBiFunction<T,U> function)
Removes checked exceptions from method signature of ThrowingToIntBiFunction .
|
<T> ToIntFunction<T> |
fromToIntFunction(ThrowingToIntFunction<T> function)
Removes checked exceptions from method signature of ThrowingToIntFunction .
|
<T,U> ToLongBiFunction<T,U> |
fromToLongBiFunction(ThrowingToLongBiFunction<T,U> function)
Removes checked exceptions from method signature of ThrowingToLongBiFunction .
|
<T> ToLongFunction<T> |
fromToLongFunction(ThrowingToLongFunction<T> function)
Removes checked exceptions from method signature of ThrowingToLongFunction .
|
<T> UnaryOperator<T> |
fromUnaryOperator(ThrowingUnaryOperator<T> operator)
Removes checked exceptions from method signature of ThrowingUnaryOperator .
|
<T,R> Function<T,R> |
function(ThrowingFunction<T,R> function)
Removes checked exceptions from method signature of ThrowingFunction .
|
<T> T |
get(ThrowingSupplier<T> supplier)
Filters out checked exceptions while running ThrowingSupplier .
|
boolean |
getAsBoolean(ThrowingBooleanSupplier supplier)
Filters out checked exceptions while running ThrowingBooleanSupplier .
|
double |
getAsDouble(ThrowingDoubleSupplier supplier)
Filters out checked exceptions while running ThrowingDoubleSupplier .
|
int |
getAsInt(ThrowingIntSupplier supplier)
Filters out checked exceptions while running ThrowingIntSupplier .
|
long |
getAsLong(ThrowingLongSupplier supplier)
Filters out checked exceptions while running ThrowingLongSupplier .
|
abstract RuntimeException |
handle(Exception exception)
Converts checked exception into an unchecked one.
|
<T> Predicate<T> |
predicate(ThrowingPredicate<T> predicate)
Removes checked exceptions from method signature of ThrowingPredicate .
|
void |
run(ThrowingRunnable runnable)
Filters out checked exceptions while running ThrowingRunnable .
|
Runnable |
runnable(ThrowingRunnable runnable)
Removes checked exceptions from method signature of ThrowingRunnable .
|
<T> Supplier<T> |
supplier(ThrowingSupplier<T> supplier)
Removes checked exceptions from method signature of ThrowingSupplier .
|
protected CheckedExceptionHandler()
CheckedExceptionHandler
.
public abstract RuntimeException handle(Exception exception)
Exceptions
class. All other methods of the CheckedExceptionHandler
call this method, but it can be also called directly.
This method represents reusable catch block that handles all checked exceptions in the same way. When invoked, it must somehow convert the checked exception into an unchecked one, usually by wrapping it. Caller is then expected to throw the returned exception. There can be special cases like Exceptions.sneak()
, which don't return at all.
Callers should not pass in RuntimeException
or other unchecked exceptions. This method might erroneously wrap such exceptions as if they are checked exceptions. Methods of this class never pass unchecked exceptions to this method.
exception
- checked exception to convert
NullPointerException
- if exception
is null
Exceptions
public final Runnable runnable(ThrowingRunnable runnable)
ThrowingRunnable
.
If runnable
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null runnable
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingRunnable(Exceptions.sneak().runnable(() -> my_throwing_lambda))
runnable
- the ThrowingRunnable
to be converted, usually a lambda
Runnable
free of checked exceptions
Exceptions
public final <T> Supplier<T> supplier(ThrowingSupplier<T> supplier)
ThrowingSupplier
.
If supplier
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null supplier
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingSupplier(Exceptions.sneak().supplier(() -> my_throwing_lambda))
T
- see Supplier
supplier
- the ThrowingSupplier
to be converted, usually a lambda
Supplier
free of checked exceptions
Exceptions
public final IntSupplier fromIntSupplier(ThrowingIntSupplier supplier)
ThrowingIntSupplier
.
If supplier
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null supplier
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingIntSupplier(Exceptions.sneak().fromIntSupplier(() -> my_throwing_lambda))
supplier
- the ThrowingIntSupplier
to be converted, usually a lambda
IntSupplier
free of checked exceptions
Exceptions
public final LongSupplier fromLongSupplier(ThrowingLongSupplier supplier)
ThrowingLongSupplier
.
If supplier
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null supplier
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingLongSupplier(Exceptions.sneak().fromLongSupplier(() -> my_throwing_lambda))
supplier
- the ThrowingLongSupplier
to be converted, usually a lambda
LongSupplier
free of checked exceptions
Exceptions
public final DoubleSupplier fromDoubleSupplier(ThrowingDoubleSupplier supplier)
ThrowingDoubleSupplier
.
If supplier
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null supplier
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingDoubleSupplier(Exceptions.sneak().fromDoubleSupplier(() -> my_throwing_lambda))
supplier
- the ThrowingDoubleSupplier
to be converted, usually a lambda
DoubleSupplier
free of checked exceptions
Exceptions
public final BooleanSupplier fromBooleanSupplier(ThrowingBooleanSupplier supplier)
ThrowingBooleanSupplier
.
If supplier
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null supplier
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingBooleanSupplier(Exceptions.sneak().fromBooleanSupplier(() -> my_throwing_lambda))
supplier
- the ThrowingBooleanSupplier
to be converted, usually a lambda
BooleanSupplier
free of checked exceptions
Exceptions
public final <T> Consumer<T> consumer(ThrowingConsumer<T> consumer)
ThrowingConsumer
.
If consumer
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null consumer
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingConsumer(Exceptions.sneak().consumer(t -> my_throwing_lambda))
T
- see Consumer
consumer
- the ThrowingConsumer
to be converted, usually a lambda
Consumer
free of checked exceptions
Exceptions
public final IntConsumer fromIntConsumer(ThrowingIntConsumer consumer)
ThrowingIntConsumer
.
If consumer
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null consumer
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingIntConsumer(Exceptions.sneak().fromIntConsumer(v -> my_throwing_lambda))
consumer
- the ThrowingIntConsumer
to be converted, usually a lambda
IntConsumer
free of checked exceptions
Exceptions
public final LongConsumer fromLongConsumer(ThrowingLongConsumer consumer)
ThrowingLongConsumer
.
If consumer
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null consumer
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingLongConsumer(Exceptions.sneak().fromLongConsumer(v -> my_throwing_lambda))
consumer
- the ThrowingLongConsumer
to be converted, usually a lambda
LongConsumer
free of checked exceptions
Exceptions
public final DoubleConsumer fromDoubleConsumer(ThrowingDoubleConsumer consumer)
ThrowingDoubleConsumer
.
If consumer
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null consumer
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingDoubleConsumer(Exceptions.sneak().fromDoubleConsumer(v -> my_throwing_lambda))
consumer
- the ThrowingDoubleConsumer
to be converted, usually a lambda
DoubleConsumer
free of checked exceptions
Exceptions
public final <T,U> BiConsumer<T,U> fromBiConsumer(ThrowingBiConsumer<T,U> consumer)
ThrowingBiConsumer
.
If consumer
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null consumer
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingBiConsumer(Exceptions.sneak().fromBiConsumer((t, u) -> my_throwing_lambda))
T
- see BiConsumer
U
- see BiConsumer
consumer
- the ThrowingBiConsumer
to be converted, usually a lambda
BiConsumer
free of checked exceptions
Exceptions
public final <T> ObjIntConsumer<T> fromObjIntConsumer(ThrowingObjIntConsumer<T> consumer)
ThrowingObjIntConsumer
.
If consumer
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null consumer
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingObjIntConsumer(Exceptions.sneak().fromObjIntConsumer((t, v) -> my_throwing_lambda))
T
- see ObjIntConsumer
consumer
- the ThrowingObjIntConsumer
to be converted, usually a lambda
ObjIntConsumer
free of checked exceptions
Exceptions
public final <T> ObjLongConsumer<T> fromObjLongConsumer(ThrowingObjLongConsumer<T> consumer)
ThrowingObjLongConsumer
.
If consumer
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null consumer
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingObjLongConsumer(Exceptions.sneak().fromObjLongConsumer((t, v) -> my_throwing_lambda))
T
- see ObjLongConsumer
consumer
- the ThrowingObjLongConsumer
to be converted, usually a lambda
ObjLongConsumer
free of checked exceptions
Exceptions
public final <T> ObjDoubleConsumer<T> fromObjDoubleConsumer(ThrowingObjDoubleConsumer<T> consumer)
ThrowingObjDoubleConsumer
.
If consumer
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null consumer
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingObjDoubleConsumer(Exceptions.sneak().fromObjDoubleConsumer((t, v) -> my_throwing_lambda))
T
- see ObjDoubleConsumer
consumer
- the ThrowingObjDoubleConsumer
to be converted, usually a lambda
ObjDoubleConsumer
free of checked exceptions
Exceptions
public final <T> Predicate<T> predicate(ThrowingPredicate<T> predicate)
ThrowingPredicate
.
If predicate
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null predicate
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingPredicate(Exceptions.sneak().predicate(t -> my_throwing_lambda))
T
- see Predicate
predicate
- the ThrowingPredicate
to be converted, usually a lambda
Predicate
free of checked exceptions
Exceptions
public final IntPredicate fromIntPredicate(ThrowingIntPredicate predicate)
ThrowingIntPredicate
.
If predicate
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null predicate
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingIntPredicate(Exceptions.sneak().fromIntPredicate(v -> my_throwing_lambda))
predicate
- the ThrowingIntPredicate
to be converted, usually a lambda
IntPredicate
free of checked exceptions
Exceptions
public final LongPredicate fromLongPredicate(ThrowingLongPredicate predicate)
ThrowingLongPredicate
.
If predicate
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null predicate
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingLongPredicate(Exceptions.sneak().fromLongPredicate(v -> my_throwing_lambda))
predicate
- the ThrowingLongPredicate
to be converted, usually a lambda
LongPredicate
free of checked exceptions
Exceptions
public final DoublePredicate fromDoublePredicate(ThrowingDoublePredicate predicate)
ThrowingDoublePredicate
.
If predicate
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null predicate
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingDoublePredicate(Exceptions.sneak().fromDoublePredicate(v -> my_throwing_lambda))
predicate
- the ThrowingDoublePredicate
to be converted, usually a lambda
DoublePredicate
free of checked exceptions
Exceptions
public final <T,U> BiPredicate<T,U> fromBiPredicate(ThrowingBiPredicate<T,U> predicate)
ThrowingBiPredicate
.
If predicate
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null predicate
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingBiPredicate(Exceptions.sneak().fromBiPredicate((t, u) -> my_throwing_lambda))
T
- see BiPredicate
U
- see BiPredicate
predicate
- the ThrowingBiPredicate
to be converted, usually a lambda
BiPredicate
free of checked exceptions
Exceptions
public final <T,R> Function<T,R> function(ThrowingFunction<T,R> function)
ThrowingFunction
.
If function
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null function
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingFunction(Exceptions.sneak().function(t -> my_throwing_lambda))
T
- see Function
R
- see Function
function
- the ThrowingFunction
to be converted, usually a lambda
Function
free of checked exceptions
Exceptions
public final <T> ToIntFunction<T> fromToIntFunction(ThrowingToIntFunction<T> function)
ThrowingToIntFunction
.
If function
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null function
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingToIntFunction(Exceptions.sneak().fromToIntFunction(v -> my_throwing_lambda))
T
- see ToIntFunction
function
- the ThrowingToIntFunction
to be converted, usually a lambda
ToIntFunction
free of checked exceptions
Exceptions
public final <R> IntFunction<R> fromIntFunction(ThrowingIntFunction<R> function)
ThrowingIntFunction
.
If function
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null function
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingIntFunction(Exceptions.sneak().fromIntFunction(v -> my_throwing_lambda))
R
- see IntFunction
function
- the ThrowingIntFunction
to be converted, usually a lambda
IntFunction
free of checked exceptions
Exceptions
public final IntToLongFunction fromIntToLongFunction(ThrowingIntToLongFunction function)
ThrowingIntToLongFunction
.
If function
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null function
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingIntToLongFunction(Exceptions.sneak().fromIntToLongFunction(v -> my_throwing_lambda))
function
- the ThrowingIntToLongFunction
to be converted, usually a lambda
IntToLongFunction
free of checked exceptions
Exceptions
public final IntToDoubleFunction fromIntToDoubleFunction(ThrowingIntToDoubleFunction function)
ThrowingIntToDoubleFunction
.
If function
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null function
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingIntToDoubleFunction(Exceptions.sneak().fromIntToDoubleFunction(v -> my_throwing_lambda))
function
- the ThrowingIntToDoubleFunction
to be converted, usually a lambda
IntToDoubleFunction
free of checked exceptions
Exceptions
public final <T> ToLongFunction<T> fromToLongFunction(ThrowingToLongFunction<T> function)
ThrowingToLongFunction
.
If function
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null function
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingToLongFunction(Exceptions.sneak().fromToLongFunction(v -> my_throwing_lambda))
T
- see ToLongFunction
function
- the ThrowingToLongFunction
to be converted, usually a lambda
ToLongFunction
free of checked exceptions
Exceptions
public final <R> LongFunction<R> fromLongFunction(ThrowingLongFunction<R> function)
ThrowingLongFunction
.
If function
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null function
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingLongFunction(Exceptions.sneak().fromLongFunction(v -> my_throwing_lambda))
R
- see LongFunction
function
- the ThrowingLongFunction
to be converted, usually a lambda
LongFunction
free of checked exceptions
Exceptions
public final LongToIntFunction fromLongToIntFunction(ThrowingLongToIntFunction function)
ThrowingLongToIntFunction
.
If function
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null function
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingLongToIntFunction(Exceptions.sneak().fromLongToIntFunction(v -> my_throwing_lambda))
function
- the ThrowingLongToIntFunction
to be converted, usually a lambda
LongToIntFunction
free of checked exceptions
Exceptions
public final LongToDoubleFunction fromLongToDoubleFunction(ThrowingLongToDoubleFunction function)
ThrowingLongToDoubleFunction
.
If function
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null function
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingLongToDoubleFunction(Exceptions.sneak().fromLongToDoubleFunction(v -> my_throwing_lambda))
function
- the ThrowingLongToDoubleFunction
to be converted, usually a lambda
LongToDoubleFunction
free of checked exceptions
Exceptions
public final <T> ToDoubleFunction<T> fromToDoubleFunction(ThrowingToDoubleFunction<T> function)
ThrowingToDoubleFunction
.
If function
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null function
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingToDoubleFunction(Exceptions.sneak().fromToDoubleFunction(v -> my_throwing_lambda))
T
- see ToDoubleFunction
function
- the ThrowingToDoubleFunction
to be converted, usually a lambda
ToDoubleFunction
free of checked exceptions
Exceptions
public final <R> DoubleFunction<R> fromDoubleFunction(ThrowingDoubleFunction<R> function)
ThrowingDoubleFunction
.
If function
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null function
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingDoubleFunction(Exceptions.sneak().fromDoubleFunction(v -> my_throwing_lambda))
R
- see DoubleFunction
function
- the ThrowingDoubleFunction
to be converted, usually a lambda
DoubleFunction
free of checked exceptions
Exceptions
public final DoubleToIntFunction fromDoubleToIntFunction(ThrowingDoubleToIntFunction function)
ThrowingDoubleToIntFunction
.
If function
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null function
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingDoubleToIntFunction(Exceptions.sneak().fromDoubleToIntFunction(v -> my_throwing_lambda))
function
- the ThrowingDoubleToIntFunction
to be converted, usually a lambda
DoubleToIntFunction
free of checked exceptions
Exceptions
public final DoubleToLongFunction fromDoubleToLongFunction(ThrowingDoubleToLongFunction function)
ThrowingDoubleToLongFunction
.
If function
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null function
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingDoubleToLongFunction(Exceptions.sneak().fromDoubleToLongFunction(v -> my_throwing_lambda))
function
- the ThrowingDoubleToLongFunction
to be converted, usually a lambda
DoubleToLongFunction
free of checked exceptions
Exceptions
public final <T> UnaryOperator<T> fromUnaryOperator(ThrowingUnaryOperator<T> operator)
ThrowingUnaryOperator
.
If operator
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null operator
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingUnaryOperator(Exceptions.sneak().fromUnaryOperator(o -> my_throwing_lambda))
T
- see UnaryOperator
operator
- the ThrowingUnaryOperator
to be converted, usually a lambda
UnaryOperator
free of checked exceptions
Exceptions
public final IntUnaryOperator fromIntUnaryOperator(ThrowingIntUnaryOperator operator)
ThrowingIntUnaryOperator
.
If operator
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null operator
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingIntUnaryOperator(Exceptions.sneak().fromIntUnaryOperator(o -> my_throwing_lambda))
operator
- the ThrowingIntUnaryOperator
to be converted, usually a lambda
IntUnaryOperator
free of checked exceptions
Exceptions
public final LongUnaryOperator fromLongUnaryOperator(ThrowingLongUnaryOperator operator)
ThrowingLongUnaryOperator
.
If operator
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null operator
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingLongUnaryOperator(Exceptions.sneak().fromLongUnaryOperator(o -> my_throwing_lambda))
operator
- the ThrowingLongUnaryOperator
to be converted, usually a lambda
LongUnaryOperator
free of checked exceptions
Exceptions
public final DoubleUnaryOperator fromDoubleUnaryOperator(ThrowingDoubleUnaryOperator operator)
ThrowingDoubleUnaryOperator
.
If operator
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null operator
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingDoubleUnaryOperator(Exceptions.sneak().fromDoubleUnaryOperator(o -> my_throwing_lambda))
operator
- the ThrowingDoubleUnaryOperator
to be converted, usually a lambda
DoubleUnaryOperator
free of checked exceptions
Exceptions
public final <T,U,R> BiFunction<T,U,R> fromBiFunction(ThrowingBiFunction<T,U,R> function)
ThrowingBiFunction
.
If function
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null function
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingBiFunction(Exceptions.sneak().fromBiFunction((t, u) -> my_throwing_lambda))
T
- see BiFunction
U
- see BiFunction
R
- see BiFunction
function
- the ThrowingBiFunction
to be converted, usually a lambda
BiFunction
free of checked exceptions
Exceptions
public final <T,U> ToIntBiFunction<T,U> fromToIntBiFunction(ThrowingToIntBiFunction<T,U> function)
ThrowingToIntBiFunction
.
If function
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null function
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingToIntBiFunction(Exceptions.sneak().fromToIntBiFunction((t, u) -> my_throwing_lambda))
T
- see ToIntBiFunction
U
- see ToIntBiFunction
function
- the ThrowingToIntBiFunction
to be converted, usually a lambda
ToIntBiFunction
free of checked exceptions
Exceptions
public final <T,U> ToLongBiFunction<T,U> fromToLongBiFunction(ThrowingToLongBiFunction<T,U> function)
ThrowingToLongBiFunction
.
If function
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null function
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingToLongBiFunction(Exceptions.sneak().fromToLongBiFunction((t, u) -> my_throwing_lambda))
T
- see ToLongBiFunction
U
- see ToLongBiFunction
function
- the ThrowingToLongBiFunction
to be converted, usually a lambda
ToLongBiFunction
free of checked exceptions
Exceptions
public final <T,U> ToDoubleBiFunction<T,U> fromToDoubleBiFunction(ThrowingToDoubleBiFunction<T,U> function)
ThrowingToDoubleBiFunction
.
If function
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null function
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingToDoubleBiFunction(Exceptions.sneak().fromToDoubleBiFunction((t, u) -> my_throwing_lambda))
T
- see ToDoubleBiFunction
U
- see ToDoubleBiFunction
function
- the ThrowingToDoubleBiFunction
to be converted, usually a lambda
ToDoubleBiFunction
free of checked exceptions
Exceptions
public final <T> BinaryOperator<T> fromBinaryOperator(ThrowingBinaryOperator<T> operator)
ThrowingBinaryOperator
.
If operator
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null operator
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingBinaryOperator(Exceptions.sneak().fromBinaryOperator((l, r) -> my_throwing_lambda))
T
- see BinaryOperator
operator
- the ThrowingBinaryOperator
to be converted, usually a lambda
BinaryOperator
free of checked exceptions
Exceptions
public final IntBinaryOperator fromIntBinaryOperator(ThrowingIntBinaryOperator operator)
ThrowingIntBinaryOperator
.
If operator
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null operator
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingIntBinaryOperator(Exceptions.sneak().fromIntBinaryOperator((l, r) -> my_throwing_lambda))
operator
- the ThrowingIntBinaryOperator
to be converted, usually a lambda
IntBinaryOperator
free of checked exceptions
Exceptions
public final LongBinaryOperator fromLongBinaryOperator(ThrowingLongBinaryOperator operator)
ThrowingLongBinaryOperator
.
If operator
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null operator
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingLongBinaryOperator(Exceptions.sneak().fromLongBinaryOperator((l, r) -> my_throwing_lambda))
operator
- the ThrowingLongBinaryOperator
to be converted, usually a lambda
LongBinaryOperator
free of checked exceptions
Exceptions
public final DoubleBinaryOperator fromDoubleBinaryOperator(ThrowingDoubleBinaryOperator operator)
ThrowingDoubleBinaryOperator
.
If operator
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null operator
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingDoubleBinaryOperator(Exceptions.sneak().fromDoubleBinaryOperator((l, r) -> my_throwing_lambda))
operator
- the ThrowingDoubleBinaryOperator
to be converted, usually a lambda
DoubleBinaryOperator
free of checked exceptions
Exceptions
public final <T> Comparator<T> comparator(ThrowingComparator<T> comparator)
ThrowingComparator
.
If comparator
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null comparator
is silently wrapped and causes NullPointerException
when executed.
Typical usage: methodTakingComparator(Exceptions.sneak().comparator((l, r) -> my_throwing_lambda))
T
- see Comparator
comparator
- the ThrowingComparator
to be converted, usually a lambda
Comparator
free of checked exceptions
Exceptions
public final CloseableScope closeable(AutoCloseable closeable)
AutoCloseable
.
If closeable
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method. Null closeable
is silently wrapped and causes NullPointerException
when executed.
Typical usage: try (var scope = Exceptions.sneak().closeable(openSomething()))
closeable
- the AutoCloseable
to be converted
CloseableScope
free of checked exceptions
Exceptions
public final void run(ThrowingRunnable runnable)
ThrowingRunnable
.
If runnable
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method.
Typical usage: Exceptions.sneak().run(() -> my_throwing_lambda))
runnable
- the ThrowingRunnable
to run, usually a lambda
NullPointerException
- if runnable
is null
Exceptions
public final <T> T get(ThrowingSupplier<T> supplier)
ThrowingSupplier
.
If supplier
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method.
Typical usage: Exceptions.sneak().get(() -> my_throwing_lambda))
T
- see Supplier
supplier
- the ThrowingSupplier
to run, usually a lambda
supplier
NullPointerException
- if supplier
is null
Exceptions
public final int getAsInt(ThrowingIntSupplier supplier)
ThrowingIntSupplier
.
If supplier
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method.
Typical usage: Exceptions.sneak().getAsInt(() -> my_throwing_lambda))
supplier
- the ThrowingIntSupplier
to run, usually a lambda
supplier
NullPointerException
- if supplier
is null
Exceptions
public final long getAsLong(ThrowingLongSupplier supplier)
ThrowingLongSupplier
.
If supplier
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method.
Typical usage: Exceptions.sneak().getAsLong(() -> my_throwing_lambda))
supplier
- the ThrowingLongSupplier
to run, usually a lambda
supplier
NullPointerException
- if supplier
is null
Exceptions
public final double getAsDouble(ThrowingDoubleSupplier supplier)
ThrowingDoubleSupplier
.
If supplier
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method.
Typical usage: Exceptions.sneak().getAsDouble(() -> my_throwing_lambda))
supplier
- the ThrowingDoubleSupplier
to run, usually a lambda
supplier
NullPointerException
- if supplier
is null
Exceptions
public final boolean getAsBoolean(ThrowingBooleanSupplier supplier)
ThrowingBooleanSupplier
.
If supplier
throws a checked exception, the exception is caught and passed to handle(Exception)
, which usually converts it to an unchecked exception, which is then thrown by this method.
Typical usage: Exceptions.sneak().getAsBoolean(() -> my_throwing_lambda))
supplier
- the ThrowingBooleanSupplier
to run, usually a lambda
supplier
NullPointerException
- if supplier
is null
Exceptions
Copyright © 2017–2020 Robert Važan. All rights reserved.