Class ExceptionUtil

java.lang.Object
com.landawn.abacus.util.ExceptionUtil

public final class ExceptionUtil extends Object
Note: This class contains the methods copied from Apache Commons and Google Guava under Apache License v2.
  • Method Details

    • registerRuntimeExceptionMapper

      public static <E extends Throwable> void registerRuntimeExceptionMapper(Class<E> exceptionClass, Function<E,RuntimeException> runtimeExceptionMapper)
      Type Parameters:
      E -
      Parameters:
      exceptionClass -
      runtimeExceptionMapper -
    • registerRuntimeExceptionMapper

      public static <E extends Throwable> void registerRuntimeExceptionMapper(Class<E> exceptionClass, Function<E,RuntimeException> runtimeExceptionMapper, boolean force)
      Type Parameters:
      E -
      Parameters:
      exceptionClass -
      runtimeExceptionMapper -
      force -
    • toRuntimeException

      public static RuntimeException toRuntimeException(Exception e)
      Parameters:
      e -
      Returns:
    • toRuntimeException

      public static RuntimeException toRuntimeException(Throwable e)
      Converts the specified Throwable to a RuntimeException if it's a checked exception or an Error, otherwise returns itself.
      Parameters:
      e -
      Returns:
      See Also:
    • toRuntimeException

      public static RuntimeException toRuntimeException(Throwable e, boolean throwIfItIsError)
      Converts the specified Throwable to a RuntimeException if it's a checked exception, or throw it if it's an Error. Otherwise returns itself.
      Parameters:
      e -
      throwIfItIsError -
      Returns:
    • tryToGetOriginalCheckedException

      public static Exception tryToGetOriginalCheckedException(Exception e)
      Parameters:
      e -
      Returns:
    • hasCause

      public static boolean hasCause(Throwable e, Class<? extends Throwable> targetExceptionType)
      Parameters:
      e -
      targetExceptionType -
      Returns:
    • hasCause

      public static boolean hasCause(Throwable e, Predicate<? super Throwable> targetExceptionTester)
      Parameters:
      e -
      targetExceptionTester -
      Returns:
    • hasSQLCause

      public static boolean hasSQLCause(Throwable e)
      Parameters:
      e -
      Returns:
    • hasIOCause

      public static boolean hasIOCause(Throwable e)
      Parameters:
      e -
      Returns:
    • isNullPointerOrIllegalArgumentException

      @Beta public static boolean isNullPointerOrIllegalArgumentException(Throwable e)
      Parameters:
      e -
      Returns:
    • listCause

      public static List<Throwable> listCause(Throwable e)
      Parameters:
      e -
      Returns:
    • firstCause

      public static Throwable firstCause(Throwable e)
      Returns the specified throwable if there is no cause found in it (throwable.getCause() == null).
      Parameters:
      e -
      Returns:
    • findCause

      public static <E extends Throwable> u.Optional<E> findCause(Throwable e, Class<? extends E> targetExceptionType)
      Type Parameters:
      E -
      Parameters:
      e -
      targetExceptionType -
      Returns:
    • findCause

      public static <E extends Throwable> u.Optional<E> findCause(Throwable e, Predicate<? super Throwable> targetExceptionTester)
      Type Parameters:
      E -
      Parameters:
      e -
      targetExceptionTester -
      Returns:
    • getStackTrace

      public static String getStackTrace(Throwable e)

      Gets the stack trace from a Throwable as a String.

      The result of this method vary by JDK version as this method uses Throwable.printStackTrace(java.io.PrintWriter). On JDK1.3 and earlier, the cause exception will not be shown unless the specified throwable alters printStackTrace.

      Parameters:
      e - the Throwable to be examined
      Returns:
      printStackTrace(PrintWriter) method
    • getErrorMessage

      public static String getErrorMessage(Throwable e)
      Parameters:
      e -
      Returns:
    • getErrorMessage

      public static String getErrorMessage(Throwable e, boolean withExceptionClassName)
      Parameters:
      e -
      withExceptionClassName -
      Returns: