-
Method Summary
Modifier and TypeMethodDescriptionstatic void
checked
(UnsafeRunnable runnable) Gracefully runs anUnsafeRunnable
.static <T> T
checked
(UnsafeSupplier<T> supplier) Gracefully gets from anUnsafeSupplier
.static <T extends Exception>
voidchecked
(Class<T> expectedExceptionClass, UnsafeRunnable runnable) Gracefully runs anUnsafeRunnable
.static <T,
T1 extends Exception>
Tchecked
(Class<T1> expectedExceptionClass, UnsafeSupplier<T> supplier) Gracefully gets from anUnsafeSupplier
.checked
(Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, UnsafeRunnable runnable) Gracefully runs anUnsafeRunnable
.checked
(Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, UnsafeSupplier<T> supplier) Gracefully gets from anUnsafeSupplier
.checked
(Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, Class<T3> expectedExceptionClass3, UnsafeRunnable runnable) Gracefully runs anUnsafeRunnable
.checked
(Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, Class<T3> expectedExceptionClass3, UnsafeSupplier<T> supplier) Gracefully gets from anUnsafeSupplier
.checked
(Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, Class<T3> expectedExceptionClass3, T argument, UnsafeConsumer<T> consumer) Gracefully supplies a value to anUnsafeConsumer
.checked
(Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, Class<T3> expectedExceptionClass3, T argument, UnsafeFunction<T, R> function) Gracefully applies anUnsafeFunction
.checked
(Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, Class<T3> expectedExceptionClass3, T firstArgument, U secondArgument, UnsafeBiConsumer<T, U> consumer) Gracefully supplies a value to anUnsafeBiConsumer
.checked
(Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, Class<T3> expectedExceptionClass3, T firstArgument, U secondArgument, UnsafeBiFunction<T, U, R> function) Gracefully applies anUnsafeBiFunction
.checked
(Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, T argument, UnsafeConsumer<T> consumer) Gracefully supplies a value to anUnsafeConsumer
.checked
(Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, T argument, UnsafeFunction<T, R> function) Gracefully applies anUnsafeFunction
.checked
(Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, T firstArgument, U secondArgument, UnsafeBiConsumer<T, U> consumer) Gracefully supplies a value to anUnsafeBiConsumer
.checked
(Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, T firstArgument, U secondArgument, UnsafeBiFunction<T, U, R> function) Gracefully applies anUnsafeBiFunction
.static <T,
T1 extends Exception>
voidchecked
(Class<T1> expectedExceptionClass, T argument, UnsafeConsumer<T> consumer) Gracefully supplies a value to anUnsafeConsumer
.static <T,
R, T1 extends Exception>
Rchecked
(Class<T1> expectedExceptionClass, T argument, UnsafeFunction<T, R> function) Gracefully applies anUnsafeFunction
.static <T,
U, T1 extends Exception>
voidchecked
(Class<T1> expectedExceptionClass, T firstArgument, U secondArgument, UnsafeBiConsumer<T, U> consumer) Gracefully supplies a value to anUnsafeBiConsumer
.static <T,
U, R, T1 extends Exception>
Rchecked
(Class<T1> expectedExceptionClass, T firstArgument, U secondArgument, UnsafeBiFunction<T, U, R> function) Gracefully applies anUnsafeBiFunction
.static Exception
Expects aThrowable
to be achecked exception
.static <T extends Exception>
TExpects aThrowable
to be a specificchecked exception
.Expects aThrowable
to be a specificchecked exception
.checked
(Throwable throwable, Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, Class<T3> expectedExceptionClass3) Expects aThrowable
to be a specificchecked exception
.static <T> void
checked
(T argument, UnsafeConsumer<T> consumer) Gracefully supplies a value to anUnsafeConsumer
.static <T,
R> R checked
(T argument, UnsafeFunction<T, R> function) Gracefully applies anUnsafeFunction
.static <T,
U> void checked
(T firstArgument, U secondArgument, UnsafeBiConsumer<T, U> consumer) Gracefully supplies a value to anUnsafeBiConsumer
.static <T,
U, R> R checked
(T firstArgument, U secondArgument, UnsafeBiFunction<T, U, R> function) Gracefully applies anUnsafeBiFunction
.static <R> R
checkedInvocation
(UnsafeSupplier<R> supplier) Gracefully invokes amethod or constructor
.static <R,
T extends Exception>
RcheckedInvocation
(Class<T> expectedExceptionClass, UnsafeSupplier<R> supplier) Gracefully invokes amethod or constructor
.checkedInvocation
(Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, UnsafeSupplier<R> supplier) Gracefully invokes amethod or constructor
.checkedInvocation
(Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, Class<T3> expectedExceptionClass3, UnsafeSupplier<R> supplier) Gracefully invokes amethod or constructor
.static <T extends AutoCloseable,
R>
Rinitialize
(T resource, UnsafeFunction<T, R> initializer) Gracefully initializes a component that depends on anAutoCloseable
resource,closing
the resource and suppressing any close errors before rethrowing a checked exception if the component fails to initialize.static void
suppress
(UnsafeRunnable... tasks) Runs a sequence of tasks with error suppression.static void
suppress
(Iterable<UnsafeRunnable> tasks) Runs a sequence of tasks with error suppression.static Throwable
suppress
(Throwable throwable, UnsafeRunnable runnable) Runs anUnsafeRunnable
and adds any exception thrown as suppressed by an another exception.static String
static void
unchecked
(UnsafeRunnable runnable) Gracefully runs anUnsafeRunnable
.static void
unchecked
(UnsafeRunnable runnable, String message) Gracefully runs anUnsafeRunnable
.static <T> T
unchecked
(UnsafeSupplier<T> supplier) Gracefully gets from anUnsafeSupplier
.static <T> T
unchecked
(UnsafeSupplier<T> supplier, String message) Gracefully gets from anUnsafeSupplier
.static RuntimeException
Expects aThrowable
to be an (unchecked)RuntimeException
.static RuntimeException
Expects aThrowable
to be an (unchecked)RuntimeException
.static <T> void
unchecked
(T argument, UnsafeConsumer<T> consumer) Gracefully supplies a value to anUnsafeConsumer
.static <T,
R> R unchecked
(T argument, UnsafeFunction<T, R> function) Gracefully applies anUnsafeFunction
.static <T,
U> void unchecked
(T firstArgument, U secondArgument, UnsafeBiConsumer<T, U> consumer) Gracefully supplies a value to anUnsafeBiConsumer
.static <T,
U, R> R unchecked
(T firstArgument, U secondArgument, UnsafeBiFunction<T, U, R> function) Gracefully applies anUnsafeBiFunction
.static <R> R
uncheckedInvocation
(UnsafeSupplier<R> supplier) Gracefully invokes a supplier assumed to wrapinvocation
.
-
Method Details
-
unchecked
Expects aThrowable
to be an (unchecked)RuntimeException
.This method may be used as an exception handler in situations where
Throwable
or one or morechecked exceptions
are thrown from a downstream invocation, but achecked exception
must not be thrown from the interface being implemented and no special handling is specified.try { // something unsafe } catch (Throwable e) { throw IuException.unchecked(e); }
- Parameters:
throwable
- AnyThrowable
- Returns:
throwable
ifRuntimeException
- Throws:
IllegalStateException
- ifthrowable
is achecked exception
orcustom throwable
Error
- ifthrowable
is anError
-
unchecked
public static RuntimeException unchecked(Throwable throwable, String message) throws IllegalStateException, Error Expects aThrowable
to be an (unchecked)RuntimeException
.This method may be used as an exception handler in situations where
Throwable
or one or morechecked exceptions
are thrown from a downstream invocation, but achecked exception
must not be thrown from the interface being implemented and no special handling is specified.try { // something unsafe } catch (Throwable e) { throw IuException.unchecked(e); }
- Parameters:
throwable
- AnyThrowable
message
- Message to use withIllegalStateException
if throwable is not aRuntimeException
orError
- Returns:
throwable
ifRuntimeException
- Throws:
IllegalStateException
- ifthrowable
is achecked exception
orcustom throwable
Error
- ifthrowable
is anError
-
checked
Expects aThrowable
to be achecked exception
.This method may be used as an exception handler in situations where
Throwable
is thrown from a downstream invocation, but onlyexception
may be thrown from the interface being implemented and special handling is not specified forcustom throwables
.try { // something unsafe } catch (Throwable e) { throw IuException.checked(e); }
- Parameters:
throwable
- AnyThrowable
- Returns:
throwable
ifException
- Throws:
IllegalStateException
- ifthrowable
is acustom throwable
Error
- ifthrowable
is anError
-
checked
public static <T extends Exception> T checked(Throwable throwable, Class<T> expectedExceptionClass) throws RuntimeException, Error, IllegalStateException Expects aThrowable
to be a specificchecked exception
.This method may be used as an exception handler in situations where
Throwable
,Exception
, or specificchecked exceptions
are thrown from a downstream invocation, but at least one of these must not be thrown from the interface being implemented and special handling is not specified for the unexpectedthrowable types
.try { // something unsafe } catch (Throwable e) { throw IuException.checked(e, ACheckedException.class); }
- Type Parameters:
T
- Expected exception type- Parameters:
throwable
- AnyThrowable
expectedExceptionClass
- Expected exception class- Returns:
throwable
ifinstanceof T
- Throws:
RuntimeException
- ifthrowable
is aRuntimeException
Error
- ifthrowable
is anError
IllegalStateException
- ifthrowable
is custom or achecked exception
other thanT
-
checked
public static <T1 extends Exception,T2 extends Exception> T1 checked(Throwable throwable, Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2) throws T2, RuntimeException, Error, IllegalStateException Expects aThrowable
to be a specificchecked exception
.This method may be used as an exception handler in situations where
Throwable
,Exception
, or specificchecked exceptions
are thrown from a downstream invocation, but at least one of these must not be thrown from the interface being implemented and special handling is not specified for the unexpectedthrowable types
.try { // something unsafe } catch (Throwable e) { throw IuException.checked(e, ACheckedException.class, AnotherCheckedException.class); }
- Type Parameters:
T1
- Expected exception typeT2
- Additional exception type that may be thrown- Parameters:
throwable
- AnyThrowable
expectedExceptionClass1
- Expected exception classexpectedExceptionClass2
- Additional exception class that may be thrown- Returns:
throwable
ifinstanceof T1
- Throws:
T2
- ifthrowable
isT2
RuntimeException
- ifthrowable
is aRuntimeException
Error
- ifthrowable
is anError
IllegalStateException
- ifthrowable
is custom or achecked exception
other thanT
be thrown
-
checked
public static <T1 extends Exception,T2 extends Exception, T1 checkedT3 extends Exception> (Throwable throwable, Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, Class<T3> expectedExceptionClass3) throws T2, T3, RuntimeException, Error, IllegalStateException Expects aThrowable
to be a specificchecked exception
.This method may be used as an exception handler in situations where
Throwable
,Exception
, or specificchecked exceptions
are thrown from a downstream invocation, but at least one of these must not be thrown from the interface being implemented and special handling is not specified for the unexpectedthrowable types
.try { // something unsafe } catch (Throwable e) { throw IuException.checked(e, ACheckedException.class, AnotherCheckedException.class, YetAnotherCheckedException.class); }
- Type Parameters:
T1
- Expected exception typeT2
- Additional exception type that may be thrownT3
- Additional exception type that may be thrown- Parameters:
throwable
- AnyThrowable
expectedExceptionClass1
- Expected exception classexpectedExceptionClass2
- Additional exception class that may be thrownexpectedExceptionClass3
- Additional exception class that may be thrown- Returns:
throwable
ifinstanceof T1
- Throws:
T2
- ifthrowable
isT2
T3
- ifthrowable
isT3
RuntimeException
- ifthrowable
is aRuntimeException
Error
- ifthrowable
is anError
IllegalStateException
- ifthrowable
is custom or achecked exception
other thanT
be thrown
-
uncheckedInvocation
Gracefully invokes a supplier assumed to wrapinvocation
.Handles
InvocationTargetException
by unwrapping the cause and re-throwing.Handles other exceptions via
unchecked(Throwable)
.- Type Parameters:
R
- result type- Parameters:
supplier
-UnsafeSupplier
assumed to wrapinvocation
.- Returns:
- result
-
checkedInvocation
Gracefully invokes amethod or constructor
.Handles
InvocationTargetException
by unwrapping the cause and re-throwing.Handles other exceptions via
checked(Throwable)
.- Type Parameters:
R
- result type- Parameters:
supplier
-UnsafeSupplier
assumed to wrapinvocation
.- Returns:
- result
- Throws:
Exception
- If invocation fails
-
checkedInvocation
public static <R,T extends Exception> R checkedInvocation(Class<T> expectedExceptionClass, UnsafeSupplier<R> supplier) throws T Gracefully invokes amethod or constructor
.Handles
InvocationTargetException
by unwrapping the cause and re-throwing.Handles other exceptions via
checked(Throwable, Class)
.- Type Parameters:
R
- result typeT
- Expected exception type- Parameters:
expectedExceptionClass
- Expected exception classsupplier
-UnsafeSupplier
assumed to wrapinvocation
.- Returns:
- result
- Throws:
T
- If invocation fails
-
checkedInvocation
public static <R,T1 extends Exception, R checkedInvocationT2 extends Exception> (Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, UnsafeSupplier<R> supplier) throws T1, T2 Gracefully invokes amethod or constructor
.Handles
InvocationTargetException
by unwrapping the cause and re-throwing.Handles other exceptions via
checked(Throwable, Class, Class)
.- Type Parameters:
R
- result typeT1
- Expected exception typeT2
- Expected exception type- Parameters:
expectedExceptionClass1
- Expected exception classexpectedExceptionClass2
- Expected exception classsupplier
-UnsafeSupplier
assumed to wrapinvocation
.- Returns:
- result
- Throws:
T1
- If invocation failsT2
- If invocation fails
-
checkedInvocation
public static <R,T1 extends Exception, R checkedInvocationT2 extends Exception, T3 extends Exception> (Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, Class<T3> expectedExceptionClass3, UnsafeSupplier<R> supplier) throws T1, T2, T3 Gracefully invokes amethod or constructor
.Handles
InvocationTargetException
by unwrapping the cause and re-throwing.Handles other exceptions via
checked(Throwable, Class, Class, Class)
.- Type Parameters:
R
- result typeT1
- Expected exception typeT2
- Expected exception typeT3
- Expected exception type- Parameters:
expectedExceptionClass1
- Expected exception classexpectedExceptionClass2
- Expected exception classexpectedExceptionClass3
- Expected exception classsupplier
-UnsafeSupplier
assumed to wrapinvocation
.- Returns:
- result
- Throws:
T1
- If invocation failsT2
- If invocation failsT3
- If invocation fails
-
unchecked
Gracefully runs anUnsafeRunnable
.Handles exceptions via
unchecked(Throwable)
.- Parameters:
runnable
- AnyUnsafeRunnable
-
unchecked
Gracefully runs anUnsafeRunnable
.Handles exceptions via
unchecked(Throwable)
.- Parameters:
runnable
- AnyUnsafeRunnable
message
- message for use withunchecked(Throwable, String)
-
checked
Gracefully runs anUnsafeRunnable
.Handles exceptions via
checked(Throwable)
.- Parameters:
runnable
- AnyUnsafeRunnable
- Throws:
Exception
- If thrown byUnsafeRunnable.run()
-
checked
public static <T extends Exception> void checked(Class<T> expectedExceptionClass, UnsafeRunnable runnable) throws T Gracefully runs anUnsafeRunnable
.Handles exceptions via
checked(Throwable, Class)
.- Type Parameters:
T
- Expected exception type- Parameters:
expectedExceptionClass
- Expected exception classrunnable
- AnyUnsafeRunnable
- Throws:
T
- If thrown byUnsafeRunnable.run()
-
checked
public static <T1 extends Exception,T2 extends Exception> void checked(Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, UnsafeRunnable runnable) throws T1, T2 Gracefully runs anUnsafeRunnable
.Handles exceptions via
checked(Throwable, Class, Class)
.- Type Parameters:
T1
- Expected exception typeT2
- Expected exception type- Parameters:
expectedExceptionClass1
- Expected exception classexpectedExceptionClass2
- Expected exception classrunnable
- AnyUnsafeRunnable
- Throws:
T1
- If thrown byUnsafeRunnable.run()
T2
- If thrown byUnsafeRunnable.run()
-
checked
public static <T1 extends Exception,T2 extends Exception, void checkedT3 extends Exception> (Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, Class<T3> expectedExceptionClass3, UnsafeRunnable runnable) throws T1, T2, T3 Gracefully runs anUnsafeRunnable
.Handles exceptions via
checked(Throwable, Class, Class, Class)
.- Type Parameters:
T1
- Expected exception typeT2
- Expected exception typeT3
- Expected exception type- Parameters:
expectedExceptionClass1
- Expected exception classexpectedExceptionClass2
- Expected exception classexpectedExceptionClass3
- Expected exception classrunnable
- AnyUnsafeRunnable
- Throws:
T1
- If thrown byUnsafeRunnable.run()
T2
- If thrown byUnsafeRunnable.run()
T3
- If thrown byUnsafeRunnable.run()
-
unchecked
Gracefully gets from anUnsafeSupplier
.Handles exceptions via
unchecked(Throwable)
.- Type Parameters:
T
- result type- Parameters:
supplier
- AnyUnsafeSupplier
- Returns:
- result
-
unchecked
Gracefully gets from anUnsafeSupplier
.Handles exceptions via
unchecked(Throwable)
.- Type Parameters:
T
- result type- Parameters:
supplier
- AnyUnsafeSupplier
message
- Message to use withunchecked(Throwable, String)
- Returns:
- result
-
checked
Gracefully gets from anUnsafeSupplier
.Handles exceptions via
checked(Throwable)
.- Type Parameters:
T
- result type- Parameters:
supplier
- AnyUnsafeSupplier
- Returns:
- result
- Throws:
Exception
- If thrown byUnsafeSupplier.get()
-
checked
public static <T,T1 extends Exception> T checked(Class<T1> expectedExceptionClass, UnsafeSupplier<T> supplier) throws T1 Gracefully gets from anUnsafeSupplier
.Handles exceptions via
checked(Throwable, Class)
.- Type Parameters:
T
- result typeT1
- Expected exception type- Parameters:
expectedExceptionClass
- Expected exception classsupplier
- AnyUnsafeSupplier
- Returns:
- result
- Throws:
T1
- If thrown byUnsafeSupplier.get()
-
checked
public static <T,T1 extends Exception, T checkedT2 extends Exception> (Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, UnsafeSupplier<T> supplier) throws T1, T2 Gracefully gets from anUnsafeSupplier
.Handles exceptions via
checked(Throwable, Class, Class)
.- Type Parameters:
T
- result typeT1
- Expected exception typeT2
- Expected exception type- Parameters:
expectedExceptionClass1
- Expected exception classexpectedExceptionClass2
- Expected exception classsupplier
- AnyUnsafeSupplier
- Returns:
- result
- Throws:
T1
- If thrown byUnsafeSupplier.get()
T2
- If thrown byUnsafeSupplier.get()
-
checked
public static <T,T1 extends Exception, T checkedT2 extends Exception, T3 extends Exception> (Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, Class<T3> expectedExceptionClass3, UnsafeSupplier<T> supplier) throws T1, T2, T3 Gracefully gets from anUnsafeSupplier
.Handles exceptions via
checked(Throwable, Class, Class, Class)
.- Type Parameters:
T
- result typeT1
- Expected exception typeT2
- Expected exception typeT3
- Expected exception type- Parameters:
expectedExceptionClass1
- Expected exception classexpectedExceptionClass2
- Expected exception classexpectedExceptionClass3
- Expected exception classsupplier
- AnyUnsafeSupplier
- Returns:
- result
- Throws:
T1
- If thrown byUnsafeSupplier.get()
T2
- If thrown byUnsafeSupplier.get()
T3
- If thrown byUnsafeSupplier.get()
-
unchecked
Gracefully supplies a value to anUnsafeConsumer
.Handles exceptions via
unchecked(Throwable)
.- Type Parameters:
T
- argument type- Parameters:
argument
- Argument forUnsafeConsumer.accept(Object)
consumer
- AnyUnsafeConsumer
-
checked
Gracefully supplies a value to anUnsafeConsumer
.Handles exceptions via
checked(Throwable)
.- Type Parameters:
T
- argument type- Parameters:
argument
- Argument forUnsafeConsumer.accept(Object)
consumer
- AnyUnsafeConsumer
- Throws:
Exception
- If thrown byUnsafeConsumer.accept(Object)
-
checked
public static <T,T1 extends Exception> void checked(Class<T1> expectedExceptionClass, T argument, UnsafeConsumer<T> consumer) throws T1 Gracefully supplies a value to anUnsafeConsumer
.Handles exceptions via
checked(Throwable, Class)
.- Type Parameters:
T
- argument typeT1
- Expected exception type- Parameters:
expectedExceptionClass
- Expected exception classargument
- Argument forUnsafeConsumer.accept(Object)
consumer
- AnyUnsafeConsumer
- Throws:
T1
- If thrown byUnsafeConsumer.accept(Object)
-
checked
public static <T,T1 extends Exception, void checkedT2 extends Exception> (Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, T argument, UnsafeConsumer<T> consumer) throws T1, T2 Gracefully supplies a value to anUnsafeConsumer
.Handles exceptions via
checked(Throwable, Class, Class)
.- Type Parameters:
T
- argument typeT1
- Expected exception typeT2
- Expected exception type- Parameters:
expectedExceptionClass1
- Expected exception classexpectedExceptionClass2
- Expected exception classargument
- Argument forUnsafeConsumer.accept(Object)
consumer
- AnyUnsafeConsumer
- Throws:
T1
- If thrown byUnsafeConsumer.accept(Object)
T2
- If thrown byUnsafeConsumer.accept(Object)
-
checked
public static <T,T1 extends Exception, void checkedT2 extends Exception, T3 extends Exception> (Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, Class<T3> expectedExceptionClass3, T argument, UnsafeConsumer<T> consumer) throws T1, T2, T3 Gracefully supplies a value to anUnsafeConsumer
.Handles exceptions via
checked(Throwable, Class, Class, Class)
.- Type Parameters:
T
- argument typeT1
- Expected exception typeT2
- Expected exception typeT3
- Expected exception type- Parameters:
expectedExceptionClass1
- Expected exception classexpectedExceptionClass2
- Expected exception classexpectedExceptionClass3
- Expected exception classargument
- Argument forUnsafeConsumer.accept(Object)
consumer
- AnyUnsafeConsumer
- Throws:
T1
- If thrown byUnsafeConsumer.accept(Object)
T2
- If thrown byUnsafeConsumer.accept(Object)
T3
- If thrown byUnsafeConsumer.accept(Object)
-
unchecked
Gracefully applies anUnsafeFunction
.Handles exceptions via
unchecked(Throwable)
.- Type Parameters:
T
- argument typeR
- result type- Parameters:
argument
- Argument toUnsafeFunction.apply(Object)
function
- AnyUnsafeFunction
- Returns:
- result
-
checked
Gracefully applies anUnsafeFunction
.Handles exceptions via
checked(Throwable)
.- Type Parameters:
T
- argument typeR
- result type- Parameters:
argument
- Argument toUnsafeFunction.apply(Object)
function
- AnyUnsafeFunction
- Returns:
- result
- Throws:
Exception
- If thrown byUnsafeFunction.apply(Object)
-
checked
public static <T,R, R checkedT1 extends Exception> (Class<T1> expectedExceptionClass, T argument, UnsafeFunction<T, R> function) throws T1Gracefully applies anUnsafeFunction
.Handles exceptions via
checked(Throwable, Class)
.- Type Parameters:
T
- argument typeR
- result typeT1
- Expected exception type- Parameters:
expectedExceptionClass
- Expected exception classargument
- Argument toUnsafeFunction.apply(Object)
function
- AnyUnsafeFunction
- Returns:
- result
- Throws:
T1
- If thrown byUnsafeFunction.apply(Object)
-
checked
public static <T,R, R checkedT1 extends Exception, T2 extends Exception> (Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, T argument, UnsafeFunction<T, R> function) throws T1, T2Gracefully applies anUnsafeFunction
.Handles exceptions via
checked(Throwable, Class, Class)
.- Type Parameters:
T
- argument typeR
- result typeT1
- Expected exception typeT2
- Expected exception type- Parameters:
expectedExceptionClass1
- Expected exception classexpectedExceptionClass2
- Expected exception classargument
- Argument toUnsafeFunction.apply(Object)
function
- AnyUnsafeFunction
- Returns:
- result
- Throws:
T1
- If thrown byUnsafeFunction.apply(Object)
T2
- If thrown byUnsafeFunction.apply(Object)
-
checked
public static <T,R, R checkedT1 extends Exception, T2 extends Exception, T3 extends Exception> (Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, Class<T3> expectedExceptionClass3, T argument, UnsafeFunction<T, R> function) throws T1, T2, T3Gracefully applies anUnsafeFunction
.Handles exceptions via
checked(Throwable, Class, Class, Class)
.- Type Parameters:
T
- argument typeR
- result typeT1
- Expected exception typeT2
- Expected exception typeT3
- Expected exception type- Parameters:
expectedExceptionClass1
- Expected exception classexpectedExceptionClass2
- Expected exception classexpectedExceptionClass3
- Expected exception classargument
- Argument toUnsafeFunction.apply(Object)
function
- AnyUnsafeFunction
- Returns:
- result
- Throws:
T1
- If thrown byUnsafeFunction.apply(Object)
T2
- If thrown byUnsafeFunction.apply(Object)
T3
- If thrown byUnsafeFunction.apply(Object)
-
unchecked
public static <T,U> void unchecked(T firstArgument, U secondArgument, UnsafeBiConsumer<T, U> consumer) Gracefully supplies a value to anUnsafeBiConsumer
.Handles exceptions via
unchecked(Throwable)
.- Type Parameters:
T
- first argument typeU
- second argument type- Parameters:
firstArgument
- First argument forUnsafeBiConsumer.accept(Object,Object)
secondArgument
- Second argument forUnsafeBiConsumer.accept(Object,Object)
consumer
- AnyUnsafeBiConsumer
-
checked
public static <T,U> void checked(T firstArgument, U secondArgument, UnsafeBiConsumer<T, U> consumer) throws ExceptionGracefully supplies a value to anUnsafeBiConsumer
.Handles exceptions via
checked(Throwable)
.- Type Parameters:
T
- first argument typeU
- second argument type- Parameters:
firstArgument
- Argument forUnsafeBiConsumer.accept(Object,Object)
secondArgument
- Second argument forUnsafeBiConsumer.accept(Object,Object)
consumer
- AnyUnsafeBiConsumer
- Throws:
Exception
- If thrown byUnsafeBiConsumer.accept(Object,Object)
-
checked
public static <T,U, void checkedT1 extends Exception> (Class<T1> expectedExceptionClass, T firstArgument, U secondArgument, UnsafeBiConsumer<T, U> consumer) throws T1Gracefully supplies a value to anUnsafeBiConsumer
.Handles exceptions via
checked(Throwable, Class)
.- Type Parameters:
T
- first argument typeU
- second argument typeT1
- Expected exception type- Parameters:
expectedExceptionClass
- Expected exception classfirstArgument
- Argument forUnsafeBiConsumer.accept(Object,Object)
secondArgument
- Second argument forUnsafeBiConsumer.accept(Object,Object)
consumer
- AnyUnsafeBiConsumer
- Throws:
T1
- If thrown byUnsafeBiConsumer.accept(Object,Object)
-
checked
public static <T,U, void checkedT1 extends Exception, T2 extends Exception> (Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, T firstArgument, U secondArgument, UnsafeBiConsumer<T, U> consumer) throws T1, T2Gracefully supplies a value to anUnsafeBiConsumer
.Handles exceptions via
checked(Throwable, Class, Class)
.- Type Parameters:
T
- first argument typeU
- second argument typeT1
- Expected exception typeT2
- Expected exception type- Parameters:
expectedExceptionClass1
- Expected exception classexpectedExceptionClass2
- Expected exception classfirstArgument
- Argument forUnsafeBiConsumer.accept(Object,Object)
secondArgument
- Second argument forUnsafeBiConsumer.accept(Object,Object)
consumer
- AnyUnsafeBiConsumer
- Throws:
T1
- If thrown byUnsafeBiConsumer.accept(Object,Object)
T2
- If thrown byUnsafeBiConsumer.accept(Object,Object)
-
checked
public static <T,U, void checkedT1 extends Exception, T2 extends Exception, T3 extends Exception> (Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, Class<T3> expectedExceptionClass3, T firstArgument, U secondArgument, UnsafeBiConsumer<T, U> consumer) throws T1, T2, T3Gracefully supplies a value to anUnsafeBiConsumer
.Handles exceptions via
checked(Throwable, Class, Class, Class)
.- Type Parameters:
T
- first argument typeU
- second argument typeT1
- Expected exception typeT2
- Expected exception typeT3
- Expected exception type- Parameters:
expectedExceptionClass1
- Expected exception classexpectedExceptionClass2
- Expected exception classexpectedExceptionClass3
- Expected exception classfirstArgument
- Argument forUnsafeBiConsumer.accept(Object,Object)
secondArgument
- Second argument forUnsafeBiConsumer.accept(Object,Object)
consumer
- AnyUnsafeBiConsumer
- Throws:
T1
- If thrown byUnsafeBiConsumer.accept(Object,Object)
T2
- If thrown byUnsafeBiConsumer.accept(Object,Object)
T3
- If thrown byUnsafeBiConsumer.accept(Object,Object)
-
unchecked
public static <T,U, R uncheckedR> (T firstArgument, U secondArgument, UnsafeBiFunction<T, U, R> function) Gracefully applies anUnsafeBiFunction
.Handles exceptions via
unchecked(Throwable)
.- Type Parameters:
T
- first argument typeU
- second argument typeR
- result type- Parameters:
firstArgument
- First argument toUnsafeBiFunction.apply(Object, Object)
secondArgument
- Second argument toUnsafeBiFunction.apply(Object, Object)
function
- AnyUnsafeFunction
- Returns:
- result
-
checked
public static <T,U, R checkedR> (T firstArgument, U secondArgument, UnsafeBiFunction<T, U, throws ExceptionR> function) Gracefully applies anUnsafeBiFunction
.Handles exceptions via
checked(Throwable)
.- Type Parameters:
T
- first argument typeU
- second argument typeR
- result type- Parameters:
firstArgument
- First argument toUnsafeBiFunction.apply(Object, Object)
secondArgument
- Second argument toUnsafeBiFunction.apply(Object, Object)
function
- AnyUnsafeBiFunction
- Returns:
- result
- Throws:
Exception
- If thrown byUnsafeBiFunction.apply(Object, Object)
-
checked
public static <T,U, R checkedR, T1 extends Exception> (Class<T1> expectedExceptionClass, T firstArgument, U secondArgument, UnsafeBiFunction<T, U, throws T1R> function) Gracefully applies anUnsafeBiFunction
.Handles exceptions via
checked(Throwable, Class)
.- Type Parameters:
T
- first argument typeU
- second argument typeR
- result typeT1
- Expected exception type- Parameters:
expectedExceptionClass
- Expected exception classfirstArgument
- First argument toUnsafeBiFunction.apply(Object, Object)
secondArgument
- Second argument toUnsafeBiFunction.apply(Object, Object)
function
- AnyUnsafeBiFunction
- Returns:
- result
- Throws:
T1
- If thrown byUnsafeBiFunction.apply(Object, Object)
-
checked
public static <T,U, R checkedR, T1 extends Exception, T2 extends Exception> (Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, T firstArgument, U secondArgument, UnsafeBiFunction<T, U, throws T1, T2R> function) Gracefully applies anUnsafeBiFunction
.Handles exceptions via
checked(Throwable, Class, Class)
.- Type Parameters:
T
- first argument typeU
- second argument typeR
- result typeT1
- Expected exception typeT2
- Expected exception type- Parameters:
expectedExceptionClass1
- Expected exception classexpectedExceptionClass2
- Expected exception classfirstArgument
- First argument toUnsafeBiFunction.apply(Object, Object)
secondArgument
- Second argument toUnsafeBiFunction.apply(Object, Object)
function
- AnyUnsafeBiFunction
- Returns:
- result
- Throws:
T1
- If thrown byUnsafeBiFunction.apply(Object, Object)
T2
- If thrown byUnsafeBiFunction.apply(Object, Object)
-
checked
public static <T,U, R checkedR, T1 extends Exception, T2 extends Exception, T3 extends Exception> (Class<T1> expectedExceptionClass1, Class<T2> expectedExceptionClass2, Class<T3> expectedExceptionClass3, T firstArgument, U secondArgument, UnsafeBiFunction<T, U, throws T1, T2, T3R> function) Gracefully applies anUnsafeBiFunction
.Handles exceptions via
checked(Throwable, Class, Class, Class)
.- Type Parameters:
T
- first argument typeU
- second argument typeR
- result typeT1
- Expected exception typeT2
- Expected exception typeT3
- Expected exception type- Parameters:
expectedExceptionClass1
- Expected exception classexpectedExceptionClass2
- Expected exception classexpectedExceptionClass3
- Expected exception classfirstArgument
- First argument toUnsafeBiFunction.apply(Object, Object)
secondArgument
- Second argument toUnsafeBiFunction.apply(Object, Object)
function
- AnyUnsafeBiFunction
- Returns:
- result
- Throws:
T1
- If thrown byUnsafeBiFunction.apply(Object, Object)
T2
- If thrown byUnsafeBiFunction.apply(Object, Object)
T3
- If thrown byUnsafeBiFunction.apply(Object, Object)
-
initialize
public static <T extends AutoCloseable,R> R initialize(T resource, UnsafeFunction<T, R> initializer) throws ExceptionGracefully initializes a component that depends on anAutoCloseable
resource,closing
the resource and suppressing any close errors before rethrowing a checked exception if the component fails to initialize.If no exception or error is thrown by
initializer
, then the resource remains open, and becomes the responsibility of the initialized component to close when finished with it.- Type Parameters:
T
-AutoCloseable
resource typeR
-UnsafeFunction
dependent component type- Parameters:
resource
- Open resourceinitializer
-UnsafeFunction
for initializing the resource- Returns:
resource
, after successfully invokinginitializationConsumer
- Throws:
Exception
- If thrown from byinitializationConsumer
-
suppress
Runs anUnsafeRunnable
and adds any exception thrown as suppressed by an another exception.This is useful for adding clean-up tasks to error handling routines related to failed initialization of closeable resources.
- Parameters:
throwable
- Throwable that willsuppress
exceptions thrown fromrunnable
.runnable
-UnsafeRunnable
; will be run, and any exceptions thrown will be suppressed bythrowable
- Returns:
- throwable if non-null; the exception thrown from runnable or null if no exception was thrown
-
suppress
Runs a sequence of tasks with error suppression.All tasks are guaranteed to run, but not guaranteed to finish. After all tasks have run, the first error encountered will be thrown; all additional errors will be suppressed.
- Parameters:
tasks
- tasks to run- Throws:
Throwable
- from the first task the fails in error
-
suppress
Runs a sequence of tasks with error suppression.All tasks are guaranteed to run, but not guaranteed to finish. After all tasks have run, the first error encountered will be thrown; all additional errors will be suppressed.
- Parameters:
tasks
- tasks to run- Throws:
Throwable
- from the first task the fails in error
-
trace
-