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 voidThrows aRuntimeExceptionif the passed exception is anInterruptedExceptionorInterruptedIOException, or if the current thread is marked interrupted.protected static Throwablestatic ThrowablegetRootCause(Throwable throwable) Gets the root cause of the givenThrowable.getThrowableList(Throwable throwable) static booleanDON'T USE THIS METHOD - INTERNAL API.static booleanstatic RuntimeExceptionWraps the exception into aRuntimeException, if needed, for re-throw.static ExceptionUnwraps 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,nullif none found or null throwable input
-
getThrowableList
-
getCause
-
checkInterrupt
Throws aRuntimeExceptionif the passed exception is anInterruptedExceptionorInterruptedIOException, 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,InterruptedExceptionandInterruptedIOException.- 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
InterruptedExceptionor 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
-