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 voidcheckInterrupt(Exception e)Throws aRuntimeExceptionif the passed exception is anInterruptedExceptionorInterruptedIOException, or if the current thread is marked interrupted.protected static ThrowablegetCause(Throwable throwable)static ThrowablegetRootCause(Throwable throwable)Gets the root cause of the givenThrowable.static List<Throwable>getThrowableList(Throwable throwable)static booleanhasInterruptedCause(Throwable e)DON'T USE THIS METHOD - INTERNAL API.static booleanisInterrupted(Throwable t)static RuntimeExceptionruntimeException(Exception e)Wraps the exception into aRuntimeException, if needed, for re-throw.static ExceptionunwrapInvoke(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,nullif none found or null throwable input
-
checkInterrupt
public static void checkInterrupt(Exception e)
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
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,InterruptedExceptionandInterruptedIOException.- 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
InterruptedExceptionor 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
-
-