org.apache.tapestry.util.exception
Class ExceptionAnalyzer

java.lang.Object
  extended by org.apache.tapestry.util.exception.ExceptionAnalyzer

public class ExceptionAnalyzer
extends Object

Analyzes an exception, creating one or more ExceptionDescriptions from it.

Version:
$Id: ExceptionAnalyzer.java 243791 2004-02-19 17:38:13Z hlship $
Author:
Howard Lewis Ship

Constructor Summary
ExceptionAnalyzer()
           
 
Method Summary
 ExceptionDescription[] analyze(Throwable exception)
          Analyzes the exceptions.
protected  Throwable buildDescription(Throwable exception)
           
protected  String[] getStackTrace(Throwable exception)
          Gets the stack trace for the exception, and converts it into an array of strings.
 boolean isExhaustive()
          If true, then stack trace is extracted for each exception.
 void reportException(Throwable exception, PrintStream stream)
          Produces a text based exception report to the provided stream.
 void setExhaustive(boolean value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExceptionAnalyzer

public ExceptionAnalyzer()
Method Detail

isExhaustive

public boolean isExhaustive()
If true, then stack trace is extracted for each exception. If false, the default, then stack trace is extracted for only the deepest exception.


setExhaustive

public void setExhaustive(boolean value)

analyze

public ExceptionDescription[] analyze(Throwable exception)
Analyzes the exceptions. This builds an ExceptionDescription for the exception. It also looks for a non-null Throwable property. If one exists, then a second ExceptionDescription is created. This continues until no more nested exceptions can be found.

The description includes a set of name/value properties (as ExceptionProperty) object. This list contains all non-null properties that are not, themselves, Throwable.

The name is the display name (not the logical name) of the property. The value is the toString() value of the property. Only properties defined in subclasses of Throwable are included.

A future enhancement will be to alphabetically sort the properties by name.


buildDescription

protected Throwable buildDescription(Throwable exception)

getStackTrace

protected String[] getStackTrace(Throwable exception)
Gets the stack trace for the exception, and converts it into an array of strings.

This involves parsing the string generated indirectly from Throwable.printStackTrace(PrintWriter). This method can get confused if the message (presumably, the first line emitted by printStackTrace()) spans multiple lines.

Different JVMs format the exception in different ways.

A possible expansion would be more flexibility in defining the pattern used. Hopefully all 'mainstream' JVMs are close enough for this to continue working.


reportException

public void reportException(Throwable exception,
                            PrintStream stream)
Produces a text based exception report to the provided stream.