com.sibvisions.util.type
Class ExceptionUtil

java.lang.Object
  extended by com.sibvisions.util.type.ExceptionUtil

public final class ExceptionUtil
extends Object

The ExceptionUtil provides common functionality for working with and processing exceptions.

Since:
2.3

Method Summary
static boolean contains(Throwable pThrowable, Class<? extends Throwable> pClass)
          Gets whether the Throwable from the chain contains a Throwable that the given Class is assignable from.
static String dump(Throwable pCause, boolean pDeep)
          Writes the Throwable and its stacktrace into a String.
static List<String> getMessages(Throwable pThrowable)
          Gets all messages in the chain starting with pThrowable.
static String getMessages(Throwable pThrowable, String pSeparator)
          Gets all messages in the chain starting with pThrowable concatenated into a String with the given separator.
static Throwable getRootCause(Throwable pThrowable)
          Gets the root cause of the given Throwable.
static
<T extends Throwable>
T
getThrowable(Throwable pThrowable, Class<T> pClass)
          Gets the Throwable from the chain that the given Class is assignable from.
static List<Throwable> getThrowables(Throwable pThrowable)
          Gets a List of all Throwables and causes including pThrowable as first element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

contains

public static boolean contains(Throwable pThrowable,
                               Class<? extends Throwable> pClass)
Gets whether the Throwable from the chain contains a Throwable that the given Class is assignable from.

Parameters:
pThrowable - the Throwable from which to start.
pClass - the Class of the Throwable that you're looking for.
Returns:
true if there is an Throwable in the chain which matches the given type.
See Also:
getThrowable(Throwable, Class), Class.isAssignableFrom(Class)

dump

public static String dump(Throwable pCause,
                          boolean pDeep)
Writes the Throwable and its stacktrace into a String. If pDeep is true also all causes will be written.

Parameters:
pCause - the Throwable to dump.
pDeep - true to dump given Throwable and all causes, false to only dump the given Throwable.
Returns:
the dumped Throwable.

getMessages

public static List<String> getMessages(Throwable pThrowable)
Gets all messages in the chain starting with pThrowable.

Parameters:
pThrowable - the Throwable at which to start.
Returns:
the List of messages.

getMessages

public static String getMessages(Throwable pThrowable,
                                 String pSeparator)
Gets all messages in the chain starting with pThrowable concatenated into a String with the given separator.

Parameters:
pThrowable - the Throwable at which to start.
pSeparator - the separator to use.
Returns:
the concatenated messages.
See Also:
getMessages(Throwable), StringUtil.concat(String, String...)

getRootCause

public static Throwable getRootCause(Throwable pThrowable)
Gets the root cause of the given Throwable.

Parameters:
pThrowable - the Throwable of which to get the root cause.
Returns:
the root cause of the given Throwable. null if pThrowable is null. pThrowable is returned if it does not have a cause.

getThrowable

public static <T extends Throwable> T getThrowable(Throwable pThrowable,
                                                   Class<T> pClass)
Gets the Throwable from the chain that the given Class is assignable from.

Type Parameters:
T - the type of the Throwable.
Parameters:
pThrowable - the Throwable from which to start.
pClass - the Class of the Throwable that you're looking for.
Returns:
the Throwable from the chain that is assignable from the given Class.
See Also:
contains(Throwable, Class), Class.isAssignableFrom(Class)

getThrowables

public static List<Throwable> getThrowables(Throwable pThrowable)
Gets a List of all Throwables and causes including pThrowable as first element.

Parameters:
pThrowable - the Throwable of which to get all causes.
Returns:
a List of all Throwables and causes including pThrowable as first element.


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.