org.jcoderz.commons.util
Class ThrowableUtil

java.lang.Object
  extended by org.jcoderz.commons.util.ThrowableUtil

public final class ThrowableUtil
extends Object

Helper class around throwables.

Author:
Andreas Mandel

Method Summary
static void collectNestedData(Loggable loggable)
          Pull up nested information.
static void fixChaining(Throwable ex)
          Tries to fix the exception chaining for the given Throwable.
static Map getProperties(Throwable thr)
          Tries to read additional property like information from this throwable and fills it in a map suitable for detailed information output.
static String toString(Throwable thr)
          Dumps the stack trace of the given throwable to its String representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

fixChaining

public static void fixChaining(Throwable ex)
Tries to fix the exception chaining for the given Throwable. Some exception classes still use a none standard way to nest exceptions. This method tries best to detect this classes and pass the nested exceptions into the standard nesting mechanism available since JDK1.4 with the throwable class. It is save to call this method several times for a give exception.

Parameters:
ex - the exception to be checked.

collectNestedData

public static void collectNestedData(Loggable loggable)
Pull up nested information. This method goes down the exception chain of the given loggable and if it find getters for properties, like getSql() adds the values of these properties as parameters to the loggable. The search is stopped when either a Loggable is found in the list, the end of the chain is reached or after MAX_NESTING_DEPTH steps down the chain.

Parameters:
loggable - the Loggable to be feed with parameters.

getProperties

public static Map getProperties(Throwable thr)
Tries to read additional property like information from this throwable and fills it in a map suitable for detailed information output.

Parameters:
thr - the throwable to analyze.
Returns:
a Map pointing from String property names to the value.

toString

public static String toString(Throwable thr)
Dumps the stack trace of the given throwable to its String representation.

Parameters:
thr - the throwable to dump the stack trace from.
Returns:
a String representation of the given throwable
See Also:
Throwable.printStackTrace()


Copyright 2007 The jCoderZ Project.