Package cz.o2.proxima.core.util
Class ExceptionUtils
- java.lang.Object
-
- cz.o2.proxima.core.util.ExceptionUtils
-
public class ExceptionUtils extends java.lang.ObjectUtilities related to exception throwing and handling.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceExceptionUtils.ThrowingBiConsumer<A,B>BiConsumer throwing exceptions.static interfaceExceptionUtils.ThrowingConsumer<T>Consumer throwing exceptions.static interfaceExceptionUtils.ThrowingFactory<T>Factory throwing exception.static interfaceExceptionUtils.ThrowingRunnableRunnable throwing exception.static interfaceExceptionUtils.ThrowingUnaryFunction<IN,OUT>Function throwing exception.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidignoring(ExceptionUtils.ThrowingRunnable runnable)Swallow any Exception.static booleanignoringInterrupted(ExceptionUtils.ThrowingRunnable runnable)Run given runnable, swallow any potentialInterruptedExceptionand set current thread's interrupted flag (if exception caught).static booleanisInterrupted(java.lang.Throwable ex)Verify that givenThrowable(or any of its causes) isInterruptedException.static voidrethrowAsIllegalStateException(java.lang.Throwable cause)Throw anIllegalStateExceptionwith given exception as cause.static voidunchecked(ExceptionUtils.ThrowingRunnable runnable)Run given runnable rethrowing exceptions asRuntimeExceptions.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> TuncheckedFactory(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 asRuntimeExceptions.- 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 potentialInterruptedExceptionand set current thread's interrupted flag (if exception caught).- Parameters:
runnable- runnable throwingInterruptedException- Returns:
trueifInterruptedExceptionwas caught
-
isInterrupted
public static boolean isInterrupted(java.lang.Throwable ex)
Verify that givenThrowable(or any of its causes) isInterruptedException.- Parameters:
ex- Throwable- Returns:
trueif ex isInterruptedException
-
rethrowAsIllegalStateException
public static void rethrowAsIllegalStateException(java.lang.Throwable cause)
Throw anIllegalStateExceptionwith given exception as cause.- Parameters:
cause- the cause ofIllegalStateException.
-
ignoring
public static void ignoring(ExceptionUtils.ThrowingRunnable runnable)
Swallow any Exception.
-
-