Package io.deephaven.util
Class FindExceptionCause
java.lang.Object
io.deephaven.util.FindExceptionCause
-
Constructor Summary
-
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.isOrCausedBy
(@NotNull Throwable original, @NotNull Class<E> expectedType) Given aThrowable
, and an expected type, return an optional that is populated if the original was an instance of the expected type or was caused by the expected type.static String
shortCauses
(@NotNull 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. -
isOrCausedBy
public static <E extends Throwable> Optional<E> isOrCausedBy(@NotNull @NotNull Throwable original, @NotNull @NotNull Class<E> expectedType) Given aThrowable
, and an expected type, return an optional that is populated if the original was an instance of the expected type or was caused by the expected type. -
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 original Throwable if none were found
-