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. |
protected static Throwable |
getCause(Throwable throwable) |
static Throwable |
getRootCause(Throwable throwable)
Gets the root cause of the given
Throwable . |
static List<Throwable> |
getThrowableList(Throwable throwable) |
static boolean |
hasInterruptedCause(Throwable e)
DON'T USE THIS METHOD - INTERNAL API.
|
static boolean |
isInterrupted(Throwable t) |
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 List<Throwable> getThrowableList(Throwable throwable)
public 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 interruptpublic static boolean hasInterruptedCause(Throwable e)
InterruptedException
or something
equivalent (for example ClosedByInterruptException
. This is a temporary method, we should rely on the
Thread.isInterrupted()
status in the future.public static boolean isInterrupted(Throwable t)
Copyright © 2018 Nuxeo. All rights reserved.