Package com.illumon.util
Class FindExceptionCause
java.lang.Object
com.illumon.util.FindExceptionCause
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Exception
Given an exception and a list of expected exception types, traverse the cause tree and return the first exception that matches the list of expected cause types.static Throwable
Given a throwable and a list of expected throwable types, traverse the cause tree and return the first exception that matches the list of expected cause types.static Throwable
findLastCause
(Throwable original, Class<? extends Throwable>... expectedTypes) Given a throwable and a list of expected throwable types, traverse the cause tree and return the last exception that matches the list of expected cause types.static Throwable
findLastCauseRequireMatch
(Throwable original, Class<? extends Throwable>... expectedTypes) Given a throwable and a list of expected throwable types, traverse the cause tree and return the last exception that matches the list of expected cause types.static String
shortCauses
(Throwable throwable, String lineSeparator) Given an exception, provide a short description of the causes.
-
Constructor Details
-
FindExceptionCause
public FindExceptionCause()
-
-
Method Details
-
findCause
@SafeVarargs public static Exception findCause(Exception original, Class<? extends Exception>... expectedTypes) Given an exception and a list of expected exception types, traverse the cause tree and return the first exception that matches the list of expected cause types. -
findCause
@SafeVarargs public static Throwable findCause(Throwable original, Class<? extends Throwable>... expectedTypes) Given a throwable and a list of expected throwable types, traverse the cause tree and return the first exception that matches the list of expected cause types. -
shortCauses
Given an exception, provide a short description of the causes. We take each cause and return a String separated by line separator and "caused by".- Parameters:
throwable
- the Throwable to get causes fromlineSeparator
- a separation string (e.g., newline or <br>)- Returns:
- the causes formatted one per line
-
findLastCause
@SafeVarargs public static Throwable findLastCause(Throwable original, Class<? extends Throwable>... expectedTypes) Given a throwable and a list of expected throwable types, traverse the cause tree and return the last exception that matches the list of expected cause types.- Parameters:
original
- the original ThrowableexpectedTypes
- the list of expected types- Returns:
- the last Throwable of one of the defined types, or the cause of the original Throwable if none were found
-
findLastCauseRequireMatch
@SafeVarargs public static Throwable findLastCauseRequireMatch(Throwable original, Class<? extends Throwable>... expectedTypes) Given a throwable and a list of expected throwable types, traverse the cause tree and return the last exception that matches the list of expected cause types.- Parameters:
original
- the original ThrowableexpectedTypes
- the list of expected types- Returns:
- the last Throwable of one of the defined types, or null if none were found
-