Package org.nuxeo.common.utils
Class ExceptionUtils
java.lang.Object
org.nuxeo.common.utils.ExceptionUtils
Provides utility methods for manipulating and examining exceptions in a generic way.
- Author:
- DM
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Throws aRuntimeException
if the passed exception is anInterruptedException
orInterruptedIOException
, or if the current thread is marked interrupted.protected static Throwable
static Throwable
getRootCause
(Throwable throwable) Gets the root cause of the givenThrowable
.getThrowableList
(Throwable throwable) static boolean
DON'T USE THIS METHOD - INTERNAL API.static boolean
static RuntimeException
Wraps the exception into aRuntimeException
, if needed, for re-throw.static Exception
Unwraps the exception if it's anInvocationTargetException
.
-
Method Details
-
getRootCause
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
-
getThrowableList
-
getCause
-
checkInterrupt
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
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
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
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
- Since:
- 9.3
-