Package org.nuxeo.common.utils
Class ExceptionUtils
- java.lang.Object
-
- org.nuxeo.common.utils.ExceptionUtils
-
public final class ExceptionUtils extends Object
Provides utility methods for manipulating and examining exceptions in a generic way.- Author:
- DM
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
checkInterrupt(Exception e)
Throws aRuntimeException
if the passed exception is anInterruptedException
orInterruptedIOException
, 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 givenThrowable
.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 aRuntimeException
, if needed, for re-throw.static Exception
unwrapInvoke(Exception e)
Unwraps the exception if it's anInvocationTargetException
.
-
-
-
Method Detail
-
getRootCause
public static Throwable getRootCause(Throwable throwable)
Gets the root cause of the givenThrowable
.This method walks through the exception chain up to the root of the exceptions tree using
Throwable.getCause()
, and returns the root exception.- Parameters:
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 exception- Returns:
- the root cause of the
Throwable
,null
if none found or null throwable input
-
checkInterrupt
public static void checkInterrupt(Exception e)
Throws aRuntimeException
if the passed exception is anInterruptedException
orInterruptedIOException
, or if the current thread is marked interrupted.- Parameters:
e
- the exception to check- Throws:
RuntimeException
- if there was an interrupt- Since:
- 7.1
-
unwrapInvoke
public static Exception unwrapInvoke(Exception e)
Unwraps the exception if it's anInvocationTargetException
.Also deals with interrupts by immediately throwing an exception.
- Parameters:
e
- the exception to unwrap- Returns:
- the unwrapped exception
- Throws:
RuntimeException
- if there was an interrupt- Since:
- 7.1
-
runtimeException
public static RuntimeException runtimeException(Exception e)
Wraps the exception into aRuntimeException
, if needed, for re-throw.Deals with
InvocationTargetException
,InterruptedException
andInterruptedIOException
.- Parameters:
e
- the exception to wrap- Returns:
- a
RuntimeException
- Throws:
RuntimeException
- if there was an interrupt- Since:
- 7.1
-
hasInterruptedCause
public static boolean hasInterruptedCause(Throwable e)
DON'T USE THIS METHOD - INTERNAL API.This helper method is used to detect if an exception is caused by an
InterruptedException
or something equivalent (for exampleClosedByInterruptException
. This is a temporary method, we should rely on theThread.isInterrupted()
status in the future.- Since:
- 9.3
-
isInterrupted
public static boolean isInterrupted(Throwable t)
- Since:
- 9.3
-
-