Package jodd.exception
Class ExceptionUtil
java.lang.Object
jodd.exception.ExceptionUtil
Few exception utilities.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbuildMessage(String message, Throwable cause) Build a message for the given base message and its cause.static StringPrints full exception stack trace, from top to root cause, into a String.static StringPrints stack trace into a String.static <T extends Throwable>
TFinds throwing cause in exception stack.static StackTraceElement[]Returns current stack trace in form of array of stack trace elements.static Throwable[]getExceptionChain(Throwable throwable) Returns exception chain starting from top up to root cause.static ThrowablegetRootCause(Throwable throwable) Introspects theThrowableto obtain the root cause.static StackTraceElement[]getStackTrace(Throwable t, String[] allow, String[] deny) Returns stack trace filtered by class names.static StackTraceElement[][]getStackTraceChain(Throwable t, String[] allow, String[] deny) Returns stack trace chain filtered by class names.static StringReturnsnon-nullmessage for a throwable.static SQLExceptionrollupSqlExceptions(Collection<SQLException> exceptions) Rolls up SQL exceptions by taking each proceeding exception and making it a child of the previous using thesetNextExceptionmethod of SQLException.static voidthrowRuntimeException(Throwable throwable) Throws checked exceptions in un-checked manner.static ThrowableunwrapThrowable(Throwable wrappedThrowable) Unwraps invocation and undeclared exceptions to real cause.static ExceptionwrapToException(Throwable throwable) static RuntimeExceptionwrapToRuntimeException(Throwable throwable) Wraps exception toRuntimeException.
-
Constructor Details
-
ExceptionUtil
public ExceptionUtil()
-
-
Method Details
-
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
Returns stack trace filtered by class names. -
getStackTraceChain
Returns stack trace chain filtered by class names. -
getExceptionChain
Returns exception chain starting from top up to root cause. -
exceptionStackTraceToString
Prints stack trace into a String. -
exceptionChainToString
Prints full exception stack trace, from top to root cause, into a String. -
buildMessage
Build a message for the given base message and its cause. -
getRootCause
Introspects theThrowableto 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
Finds throwing cause in exception stack. Returns throwable object if cause class is matched. Otherwise, returnsnull. -
rollupSqlExceptions
Rolls up SQL exceptions by taking each proceeding exception and making it a child of the previous using thesetNextExceptionmethod of SQLException. -
throwRuntimeException
Throws checked exceptions in un-checked manner. -
message
Returnsnon-nullmessage for a throwable. -
wrapToRuntimeException
Wraps exception toRuntimeException. -
wrapToException
-
unwrapThrowable
Unwraps invocation and undeclared exceptions to real cause.
-