Object
Unchecked
This class allows you to execute functions which throw checked exceptions in a way if they were
throwing unchecked RuntimeException.
For example given method which throws checked Exception:
int m() throws Exception {
return 0;
}
Instead of writing:
try { m(); } catch (Exception e) { throw new RuntimeException(e); }
You can use this class:
getInt(this::m);
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T1,
T2, E extends Exception>
voidaccept
(ThrowingBiConsumer<T1, T2, E> c, T1 t1, T2 t2) Executes given biconsumer with a given arguments and catch all checked exceptions.static <T,
E extends Exception>
voidaccept
(ThrowingConsumer<T, E> c, T t) Executes given consumer with a given argument and catch all checked exceptions.static <E extends Exception>
voidacceptInt
(ThrowingIntConsumer<E> c, int t) Executes given consumer with a given argument and catch all checked exceptions.static <A,
R, E extends Exception>
Rapply
(ThrowingFunction<A, R, E> s, A a) Executes given function with a given argument and catch all checked exceptions.static <R,
E extends Exception>
Rget
(ThrowingSupplier<R, E> s) Executes given supplier and catch all checked exceptions.static <E extends Exception>
booleanExecutes given boolean supplier and catch all checked exceptions.static <E extends Exception>
intgetInt
(ThrowingIntSupplier<E> s) Executes given int supplier and catch all checked exceptions.static <E extends Exception>
voidrun
(ThrowingRunnable<E> s) Executes given runnable and catch all checked exceptions.static <T1,
T2, E extends Exception>
BiConsumer<T1, T2> wrapAccept
(ThrowingBiConsumer<T1, T2, E> c) Accepts ThrowingConsumer which throws checked exception and converts it to Consumer which throws unchecked onewrapAccept
(ThrowingConsumer<T, E> c) Accepts ThrowingConsumer which throws checked exception and converts it to Consumer which throws unchecked onewrapAccept
(ThrowingConsumer<T, E> c, Exception baseException) Accepts ThrowingConsumer which throws any exception and converts it to Consumer which will catch them and suppress into baseExceptionstatic <E extends Exception>
IntConsumerAccepts ThrowingConsumer which throws checked exception and converts it to Consumer which throws unchecked onewrapApply
(ThrowingFunction<A, R, E> f) Accepts ThrowingFunction which throws checked exception and converts it to Function which throws unchecked onewrapGet
(ThrowingSupplier<R, E> s) Accepts ThrowingSupplier which throws checked exception and converts it to Supplier which throws unchecked onestatic <E extends Exception>
IntSupplierAccepts ThrowingIntSupplier which throws checked exception and converts it to IntSupplier which throws unchecked onewrapRun
(ThrowingRunnable<E> r) Accepts ThrowingRunnable which throws checked exception and converts it to runnable which throws unchecked one
-
Constructor Details
-
Unchecked
public Unchecked()
-
-
Method Details
-
get
Executes given supplier and catch all checked exceptions. If checked exception is thrown it is wrapped into unchecked RuntimeException and is thrown further. -
getInt
Executes given int supplier and catch all checked exceptions. If checked exception is thrown it is wrapped into unchecked RuntimeException and is thrown further. -
getBoolean
Executes given boolean supplier and catch all checked exceptions. If checked exception is thrown it is wrapped into unchecked RuntimeException and is thrown further. -
run
Executes given runnable and catch all checked exceptions. If checked exception is thrown it is wrapped into unchecked RuntimeException and is thrown further. -
apply
Executes given function with a given argument and catch all checked exceptions. If checked exception is thrown it is wrapped into unchecked RuntimeException and is thrown further. -
accept
Executes given consumer with a given argument and catch all checked exceptions. If checked exception is thrown it is wrapped into unchecked RuntimeException and is thrown further. -
accept
public static <T1,T2, void acceptE extends Exception> (ThrowingBiConsumer<T1, T2, E> c, T1 t1, T2 t2) Executes given biconsumer with a given arguments and catch all checked exceptions. If checked exception is thrown it is wrapped into unchecked RuntimeException and is thrown further. -
acceptInt
Executes given consumer with a given argument and catch all checked exceptions. If checked exception is thrown it is wrapped into unchecked RuntimeException and is thrown further. -
wrapRun
Accepts ThrowingRunnable which throws checked exception and converts it to runnable which throws unchecked one -
wrapGet
Accepts ThrowingSupplier which throws checked exception and converts it to Supplier which throws unchecked one -
wrapGetInt
Accepts ThrowingIntSupplier which throws checked exception and converts it to IntSupplier which throws unchecked one -
wrapApply
Accepts ThrowingFunction which throws checked exception and converts it to Function which throws unchecked one -
wrapAccept
Accepts ThrowingConsumer which throws checked exception and converts it to Consumer which throws unchecked one -
wrapAccept
public static <T,E extends Exception> Consumer<T> wrapAccept(ThrowingConsumer<T, E> c, Exception baseException) Accepts ThrowingConsumer which throws any exception and converts it to Consumer which will catch them and suppress into baseException -
wrapAccept
public static <T1,T2, BiConsumer<T1,E extends Exception> T2> wrapAccept(ThrowingBiConsumer<T1, T2, E> c) Accepts ThrowingConsumer which throws checked exception and converts it to Consumer which throws unchecked one -
wrapAcceptInt
Accepts ThrowingConsumer which throws checked exception and converts it to Consumer which throws unchecked one
-