ContactCenters
V. 0.9.9.

umontreal.iro.lecuyer.util
Class ExceptionUtil

java.lang.Object
  extended by umontreal.iro.lecuyer.util.ExceptionUtil

public class ExceptionUtil
extends Object

Provides helper methods to format exceptions in a more compact way than the default exception formatting. The default behavior of the Java Virtual Machine when an uncaught exception occurs is to call the Throwable.printStackTrace() method in order to display the full stack trace on the console. This produces a rather verbose output, especially if the exception has a cause, i.e., Throwable.getCause() returns true. However, for some exception types, e.g., IOException, it might be sufficient to display only the exception class name and message. This can be done by Throwable.toString(), but the cause of the exception is then lost. This class provides the throwableToString(Throwable) which can format and return a short version of the a throwable's cause chain. Methods are also provided to install a default exception handler which calls throwableToString(Throwable) instead of Throwable.printStackTrace().


Constructor Summary
ExceptionUtil()
           
 
Method Summary
static String formatMemoryStatus()
          Constructs and returns a string giving memory status of the virtual machine.
static void replaceDefaultExceptionHandler()
          Sets the uncaught exception handler to use throwableToString(Throwable) to print exceptions, i.e., instances of Exception.
static String throwableToString(Throwable throwable)
          Converts the throwable throwable to a string, and returns the constructed string.
 
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

throwableToString

public static String throwableToString(Throwable throwable)
Converts the throwable throwable to a string, and returns the constructed string. This method uses Throwable.toString() to get a string from the given throwable, and all its causes. The formatting is similar to the default way Java prints exceptions, but stack trace elements are omitted. However, if the umontreal.iro.lecuyer.util.PrintStackTrace property is set to true, the full stack trace is also formatted for each throwable.

Parameters:
throwable - the throwable to convert.
Returns:
the string corresponding to the throwable.

replaceDefaultExceptionHandler

public static void replaceDefaultExceptionHandler()
Sets the uncaught exception handler to use throwableToString(Throwable) to print exceptions, i.e., instances of Exception. Other instances of Throwable, e.g., instances of Error, are printed using Throwable.printStackTrace().


formatMemoryStatus

public static String formatMemoryStatus()
Constructs and returns a string giving memory status of the virtual machine. This string gives the free, available and maximal memory of the JVM.

Returns:
the string with memory status.

ContactCenters
V. 0.9.9.

To submit a bug or ask questions, send an e-mail to Richard Simard.