jodd.exception
Class ExceptionUtil

java.lang.Object
  extended by jodd.exception.ExceptionUtil

public class ExceptionUtil
extends java.lang.Object

Few exception utilities.


Constructor Summary
ExceptionUtil()
           
 
Method Summary
static java.lang.String buildMessage(java.lang.String message, java.lang.Throwable cause)
          Build a message for the given base message and its cause.
static java.lang.String exceptionChainToString(java.lang.Throwable t)
          Prints full exception stack trace, from top to root cause, into a String.
static java.lang.String exceptionToString(java.lang.Throwable t)
          Prints stack trace into a String.
static java.lang.Exception extractTargetException(java.lang.reflect.InvocationTargetException itex)
           
static
<T extends java.lang.Throwable>
T
findCause(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.Throwable getRootCause(java.lang.Throwable throwable)
          Introspects the Throwable to 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.sql.SQLException rollupSqlExceptions(java.util.List<java.sql.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.
static void throwException(java.lang.Throwable throwable)
          Throws checked exceptions in un-checked manner.
static void throwExceptionAlt(java.lang.Throwable throwable)
          Throws checked exceptions in un-checked manner.
static void throwTargetException(java.lang.reflect.InvocationTargetException itex)
          Throws target of InvocationTargetException if it is exception.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExceptionUtil

public ExceptionUtil()
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.


exceptionToString

public static java.lang.String exceptionToString(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 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 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, returns null.


rollupSqlExceptions

public static java.sql.SQLException rollupSqlExceptions(java.util.List<java.sql.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.


throwTargetException

public static void throwTargetException(java.lang.reflect.InvocationTargetException itex)
                                 throws java.lang.Exception
Throws target of InvocationTargetException if it is exception.

Throws:
java.lang.Exception

extractTargetException

public static java.lang.Exception extractTargetException(java.lang.reflect.InvocationTargetException itex)

throwExceptionAlt

public static void throwExceptionAlt(java.lang.Throwable throwable)
Throws checked exceptions in un-checked manner. Uses deprecated method.

See Also:
throwException(Throwable)

throwException

public static void throwException(java.lang.Throwable throwable)
Throws checked exceptions in un-checked manner.

See Also:
throwException(Throwable)


Copyright © 2003-2012 Jodd Team