Package cz.o2.proxima.core.util
Class ExceptionUtils
- java.lang.Object
-
- cz.o2.proxima.core.util.ExceptionUtils
-
public class ExceptionUtils extends java.lang.Object
Utilities related to exception throwing and handling.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ExceptionUtils.ThrowingBiConsumer<A,B>
BiConsumer throwing exceptions.static interface
ExceptionUtils.ThrowingConsumer<T>
Consumer throwing exceptions.static interface
ExceptionUtils.ThrowingFactory<T>
Factory throwing exception.static interface
ExceptionUtils.ThrowingRunnable
Runnable throwing exception.static interface
ExceptionUtils.ThrowingUnaryFunction<IN,OUT>
Function throwing exception.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
ignoringInterrupted(ExceptionUtils.ThrowingRunnable runnable)
Run given runnable, swallow any potentialInterruptedException
and set current thread's interrupted flag (if exception caught).static boolean
isInterrupted(java.lang.Throwable ex)
Verify that givenThrowable
(or any of its causes) isInterruptedException
.static void
rethrowAsIllegalStateException(java.lang.Throwable cause)
Throw anIllegalStateException
with given exception as cause.static void
unchecked(ExceptionUtils.ThrowingRunnable runnable)
Run given runnable rethrowing exceptions asRuntimeException
s.static <A,B>
BiConsumer<A,B>uncheckedBiConsumer(ExceptionUtils.ThrowingBiConsumer<A,B> wrap)
static <T> Consumer<T>
uncheckedConsumer(ExceptionUtils.ThrowingConsumer<T> wrap)
Wrap consumer throwing exceptions to regular consumer.static <T> T
uncheckedFactory(ExceptionUtils.ThrowingFactory<T> factory)
Run given factory and return result.static <IN,OUT>
UnaryFunction<IN,OUT>uncheckedFn(ExceptionUtils.ThrowingUnaryFunction<IN,OUT> fn)
Wrap throwing unary function as regular one.
-
-
-
Method Detail
-
uncheckedConsumer
public static <T> Consumer<T> uncheckedConsumer(ExceptionUtils.ThrowingConsumer<T> wrap)
Wrap consumer throwing exceptions to regular consumer.- Type Parameters:
T
- type parameter- Parameters:
wrap
- the consumer to wrap- Returns:
- regular consumer
-
uncheckedBiConsumer
public static <A,B> BiConsumer<A,B> uncheckedBiConsumer(ExceptionUtils.ThrowingBiConsumer<A,B> wrap)
-
unchecked
public static void unchecked(ExceptionUtils.ThrowingRunnable runnable)
Run given runnable rethrowing exceptions asRuntimeException
s.- Parameters:
runnable
- the runnable to run
-
uncheckedFactory
public static <T> T uncheckedFactory(ExceptionUtils.ThrowingFactory<T> factory)
Run given factory and return result.- Type Parameters:
T
- type parameter- Parameters:
factory
- the factory that throws exceptions- Returns:
- created instance of the factory
-
uncheckedFn
public static <IN,OUT> UnaryFunction<IN,OUT> uncheckedFn(ExceptionUtils.ThrowingUnaryFunction<IN,OUT> fn)
Wrap throwing unary function as regular one.- Type Parameters:
IN
- input type parameterOUT
- output type parameter- Parameters:
fn
- the function to wrap- Returns:
- regular unary function
-
ignoringInterrupted
public static boolean ignoringInterrupted(ExceptionUtils.ThrowingRunnable runnable)
Run given runnable, swallow any potentialInterruptedException
and set current thread's interrupted flag (if exception caught).- Parameters:
runnable
- runnable throwingInterruptedException
- Returns:
true
ifInterruptedException
was caught
-
isInterrupted
public static boolean isInterrupted(java.lang.Throwable ex)
Verify that givenThrowable
(or any of its causes) isInterruptedException
.- Parameters:
ex
- Throwable- Returns:
true
if ex isInterruptedException
-
rethrowAsIllegalStateException
public static void rethrowAsIllegalStateException(java.lang.Throwable cause)
Throw anIllegalStateException
with given exception as cause.- Parameters:
cause
- the cause ofIllegalStateException
.
-
-