Class ExceptionUtil

java.lang.Object
jodd.exception.ExceptionUtil

public class ExceptionUtil extends Object
Few exception utilities.
  • Constructor Details

    • ExceptionUtil

      public ExceptionUtil()
  • Method Details

    • getCurrentStackTrace

      public static StackTraceElement[] getCurrentStackTrace()
      Returns current stack trace in form of array of stack trace elements. First stack trace element is removed. Since an exception is thrown internally, this method is slow.
    • getStackTrace

      public static StackTraceElement[] getStackTrace(Throwable t, String[] allow, String[] deny)
      Returns stack trace filtered by class names.
    • getStackTraceChain

      public static StackTraceElement[][] getStackTraceChain(Throwable t, String[] allow, String[] deny)
      Returns stack trace chain filtered by class names.
    • getExceptionChain

      public static Throwable[] getExceptionChain(Throwable throwable)
      Returns exception chain starting from top up to root cause.
    • exceptionStackTraceToString

      public static String exceptionStackTraceToString(Throwable t)
      Prints stack trace into a String.
    • exceptionChainToString

      public static String exceptionChainToString(Throwable t)
      Prints full exception stack trace, from top to root cause, into a String.
    • buildMessage

      public static String buildMessage(String message, Throwable cause)
      Build a message for the given base message and its cause.
    • getRootCause

      public static Throwable getRootCause(Throwable throwable)
      Introspects the Throwable to obtain the root cause.

      This method walks through the exception chain to the last element, "root" of the tree, and returns that exception. If no root cause found returns provided throwable.

    • findCause

      public static <T extends Throwable> T findCause(Throwable throwable, Class<T> cause)
      Finds throwing cause in exception stack. Returns throwable object if cause class is matched. Otherwise, returns null.
    • rollupSqlExceptions

      public static SQLException rollupSqlExceptions(Collection<SQLException> exceptions)
      Rolls up SQL exceptions by taking each proceeding exception and making it a child of the previous using the setNextException method of SQLException.
    • throwRuntimeException

      public static void throwRuntimeException(Throwable throwable)
      Throws checked exceptions in un-checked manner.
    • message

      public static String message(Throwable throwable)
      Returns non-null message for a throwable.
    • wrapToRuntimeException

      public static RuntimeException wrapToRuntimeException(Throwable throwable)
      Wraps exception to RuntimeException.
    • wrapToException

      public static Exception wrapToException(Throwable throwable)
    • unwrapThrowable

      public static Throwable unwrapThrowable(Throwable wrappedThrowable)
      Unwraps invocation and undeclared exceptions to real cause.