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(Throwable e)
      To runtime exception.
      Parameters:
      e -
      Returns:
      See Also:
    • tryToGetOriginalCheckedException

      public static Exception tryToGetOriginalCheckedException(Exception e)
    • hasCause

      public static boolean hasCause(Throwable throwable, Class<? extends Throwable> targetExceptionType)
    • hasCause

      public static boolean hasCause(Throwable throwable, Predicate<? super Throwable> targetExceptionTester)
    • hasSQLCause

      public static boolean hasSQLCause(Throwable throwable)
    • hasIOCause

      public static boolean hasIOCause(Throwable throwable)
    • listCause

      public static List<Throwable> listCause(Throwable throwable)
    • firstCause

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

      public static String getStackTrace(Throwable throwable)

      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:
      throwable - the Throwable to be examined
      Returns:
      printStackTrace(PrintWriter) method
    • getMessage

      @Deprecated @Internal public static String getMessage(Throwable e)
      Deprecated.
      replaced by
      invalid @link
      {@link #getErrorMessage(Throwable, true)
      }
      Gets the error msg.
      Parameters:
      e -
      Returns:
    • getErrorMessage

      public static String getErrorMessage(Throwable e)
    • getErrorMessage

      public static String getErrorMessage(Throwable e, boolean withExceptionClassName)