Class FindExceptionCause

java.lang.Object
com.illumon.util.FindExceptionCause

public class FindExceptionCause
extends Object
  • Constructor Details

  • 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

      public static String shortCauses​(@NotNull Throwable throwable, String lineSeparator)
      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 from
      lineSeparator - 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 Throwable
      expectedTypes - the list of expected types
      Returns:
      the last Throwable of one of the defined types, or the original Throwable if none were found