public final class ExceptionUtils extends Object
Modifier and Type | Method and Description |
---|---|
static void |
checkInterrupt(Exception e)
Throws a
RuntimeException if the passed exception is an InterruptedException or
InterruptedIOException , or if the current thread is marked interrupted. |
static Throwable |
getRootCause(Throwable throwable)
Gets the root cause of the given
Throwable . |
static RuntimeException |
runtimeException(Exception e)
Wraps the exception into a
RuntimeException , if needed, for re-throw. |
static Exception |
unwrapInvoke(Exception e)
Unwraps the exception if it's an
InvocationTargetException . |
public static Throwable getRootCause(Throwable throwable)
Throwable
.
This method walks through the exception chain up to the root of the exceptions tree using
Throwable.getCause()
, and returns the root exception.
throwable
- the throwable to get the root cause for, may be null - this is to avoid throwing other
un-interesting exception when handling a business-important exceptionThrowable
, null
if none found or null throwable inputpublic static void checkInterrupt(Exception e)
RuntimeException
if the passed exception is an InterruptedException
or
InterruptedIOException
, or if the current thread is marked interrupted.e
- the exception to checkRuntimeException
- if there was an interruptpublic static Exception unwrapInvoke(Exception e)
InvocationTargetException
.
Also deals with interrupts by immediately throwing an exception.
e
- the exception to unwrapRuntimeException
- if there was an interruptpublic static RuntimeException runtimeException(Exception e)
RuntimeException
, if needed, for re-throw.
Deals with InvocationTargetException
, InterruptedException
and InterruptedIOException
.
e
- the exception to wrapRuntimeException
RuntimeException
- if there was an interruptCopyright © 2015 Nuxeo SA. All rights reserved.