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