org.rhq.core.util.exception
Class ThrowableUtil

java.lang.Object
  extended by org.rhq.core.util.exception.ThrowableUtil

public class ThrowableUtil
extends Object

Utilities for working with throwables and their messages.

Author:
John Mazzitelli

Method Summary
static String getAllMessages(Throwable t)
          Same as getAllMessages(Throwable, boolean) with the "include exception name" parameter set to true.
static String getAllMessages(Throwable t, boolean includeExceptionName)
          Returns all the messages for the throwable and all of its causes in one long string.
static String getAllMessages(Throwable t, boolean includeExceptionNames, int maxSize)
          Generates a string with all exception messages similarly to getAllMessages(Throwable, boolean) but limits the length of the string to the provided limit.
static String[] getAllMessagesArray(Throwable t)
          Same as getAllMessagesArray(Throwable, boolean) with the "include exception name" parameter set to true.
static String[] getAllMessagesArray(Throwable t, boolean includeExceptionName)
          Returns all the messages for the throwable and all of its causes.
static String getAllSqlExceptionMessages(SQLException t)
          Same as #getAllSqlExceptionMessages(Throwable, boolean) with the "include exception name" parameter set to true.
static String getAllSqlExceptionMessages(SQLException t, boolean includeExceptionName)
          Returns all the messages for the SQL Exception and all of its next exceptions in one long string.
static String[] getAllSqlExceptionMessagesArray(SQLException t)
          Same as getAllSqlExceptionMessagesArray(SQLException, boolean) with the "include exception name" parameter set to true.
static String[] getAllSqlExceptionMessagesArray(SQLException t, boolean includeExceptionName)
          Returns all the messages for the SQL Exception and all of its causes.
static String getRootMessage(Throwable t)
           
static String getStackAsString(Throwable t)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAllMessages

public static String getAllMessages(Throwable t,
                                    boolean includeExceptionName)
Returns all the messages for the throwable and all of its causes in one long string. This is useful for logging an exception when you don't want to dump the entire stack trace but you still want to see the throwable and all of its causes.

Parameters:
t - the top throwable (may be null)
includeExceptionName - if true, the exception name will prefix all messages
Returns:
string containing the throwable's message and its causes' messages in the order of the causes (the lowest nested throwable's message appears last in the string)

getAllMessages

public static final String getAllMessages(Throwable t,
                                          boolean includeExceptionNames,
                                          int maxSize)
Generates a string with all exception messages similarly to getAllMessages(Throwable, boolean) but limits the length of the string to the provided limit. The messages are left out of the resulting string in the following manner:

Parameters:
t -
includeExceptionNames -
maxSize - the maximum size of the message. If < 0, the output is not limited.
Returns:

getAllMessages

public static String getAllMessages(Throwable t)
Same as getAllMessages(Throwable, boolean) with the "include exception name" parameter set to true.

Parameters:
t - the top throwable (may be null)
Returns:
string containing the throwable's message and its causes' messages in the order of the causes (the lowest nested throwable's message appears last in the string)

getAllMessagesArray

public static String[] getAllMessagesArray(Throwable t,
                                           boolean includeExceptionName)
Returns all the messages for the throwable and all of its causes.

Parameters:
t - the top throwable (may be null)
includeExceptionName - if true, the exception name will prefix all messages
Returns:
array of strings containing the throwable's message and its causes' messages in the order of the causes (the lowest nested throwable's message appears last)

getAllMessagesArray

public static String[] getAllMessagesArray(Throwable t)
Same as getAllMessagesArray(Throwable, boolean) with the "include exception name" parameter set to true.

Parameters:
t - the top throwable (may be null)
Returns:
string containing the throwable's message and its causes' messages in the order of the causes (the lowest nested throwable's message appears last in the string)

getAllSqlExceptionMessages

public static String getAllSqlExceptionMessages(SQLException t,
                                                boolean includeExceptionName)
Returns all the messages for the SQL Exception and all of its next exceptions in one long string.

Parameters:
t - the top SQL Exception (may be null)
includeExceptionName - if true, the exception name will prefix all messages
Returns:
string containing the SQL Exception's message and its next exception's messages in order

getAllSqlExceptionMessages

public static String getAllSqlExceptionMessages(SQLException t)
Same as #getAllSqlExceptionMessages(Throwable, boolean) with the "include exception name" parameter set to true.

Parameters:
t - the top sql exception (may be null)
Returns:
string containing the SQL Exception's message and its next exception's messages in order

getAllSqlExceptionMessagesArray

public static String[] getAllSqlExceptionMessagesArray(SQLException t,
                                                       boolean includeExceptionName)
Returns all the messages for the SQL Exception and all of its causes.

Parameters:
t - the top SQL Exception (may be null)
includeExceptionName - if true, the exception name will prefix all messages
Returns:
strings containing the SQL Exception's message and its next exception's messages in order

getAllSqlExceptionMessagesArray

public static String[] getAllSqlExceptionMessagesArray(SQLException t)
Same as getAllSqlExceptionMessagesArray(SQLException, boolean) with the "include exception name" parameter set to true.

Parameters:
t - the top sql exception (may be null)
Returns:
strings containing the SQL Exception's message and its next exception's messages in order

getStackAsString

public static String getStackAsString(Throwable t)

getRootMessage

public static String getRootMessage(Throwable t)


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.