Methods Summary |
---|
public java.lang.String | getMessage(int index)Returns the error message of the Throwable in the chain
of Throwable s at the specified index, numbererd from 0.
Throwable t = this.getThrowable( index );
if ( Nestable.class.isInstance( t ) ) {
return ( ( Nestable ) t ).getMessage( 0 );
}
else {
return t.getMessage();
}
|
public java.lang.String | getMessage(java.lang.String baseMsg)Returns the full message contained by the Nestable
and any nested Throwable s.
StringBuffer msg = new StringBuffer();
if ( baseMsg != null ) {
msg.append( baseMsg );
}
Throwable nestedCause = ExceptionUtils.getCause( this.nestable );
if ( nestedCause != null ) {
String causeMsg = nestedCause.getMessage();
if ( causeMsg != null ) {
if ( baseMsg != null ) {
msg.append( ": " );
}
msg.append( causeMsg );
}
}
return ( msg.length() > 0 ? msg.toString() : null );
|
public java.lang.String[] | getMessages()Returns the error message of this and any nested Throwable s
in an array of Strings, one element for each message. Any
Throwable not containing a message is represented in the
array by a null. This has the effect of cause the length of the returned
array to be equal to the result of the {@link #getThrowableCount()}
operation.
Throwable[] throwables = this.getThrowables();
String[] msgs = new String[throwables.length];
for ( int i = 0; i < throwables.length; i++ ) {
msgs[i] = Nestable.class.isInstance( throwables[i] ) ?
( ( Nestable ) throwables[i] ).getMessage( 0 ) :
throwables[i].getMessage();
}
return msgs;
|
protected java.lang.String[] | getStackFrames(java.lang.Throwable t)Captures the stack trace associated with the specified
Throwable object, decomposing it into a list of
stack frames.
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter( sw, true );
// Avoid infinite loop between decompose() and printStackTrace().
if ( t instanceof Nestable ) {
( ( Nestable ) t ).printPartialStackTrace( pw );
}
else {
t.printStackTrace( pw );
}
return ExceptionUtils.getStackFrames( sw.getBuffer().toString() );
|
public java.lang.Throwable | getThrowable(int index)Returns the Throwable in the chain of
Throwable s at the specified index, numbererd from 0.
if ( index == 0 ) {
return this.nestable;
}
Throwable[] throwables = this.getThrowables();
return throwables[index];
|
public int | getThrowableCount()Returns the number of Throwable s contained in the
Nestable contained by this delegate.
return ExceptionUtils.getThrowableCount( this.nestable );
|
public java.lang.Throwable[] | getThrowables()Returns this delegate's Nestable and any nested
Throwable s in an array of Throwable s, one
element for each Throwable .
return ExceptionUtils.getThrowables( this.nestable );
|
public int | indexOfThrowable(java.lang.Class type, int fromIndex)Returns the index, numbered from 0, of the first Throwable
that matches the specified type in the chain of Throwable s
held in this delegate's Nestable with an index greater than
or equal to the specified index, or -1 if the type is not found.
if ( fromIndex < 0 ) {
throw new IndexOutOfBoundsException( "The start index was out of bounds: " + fromIndex );
}
Throwable[] throwables = ExceptionUtils.getThrowables( this.nestable );
if ( fromIndex >= throwables.length ) {
throw new IndexOutOfBoundsException( "The start index was out of bounds: "
+ fromIndex + " >= " + throwables.length );
}
for ( int i = fromIndex; i < throwables.length; i++ ) {
if ( throwables[i].getClass().equals( type ) ) {
return i;
}
}
return -1;
|
public void | printStackTrace(java.io.PrintStream out)Prints the stack trace of this exception to the specified
stream.
synchronized ( out ) {
PrintWriter pw = new PrintWriter( out, false );
printStackTrace( pw );
// Flush the PrintWriter before it's GC'ed.
pw.flush();
}
|
public void | printStackTrace(java.io.PrintWriter out)Prints the stack trace of this exception to the specified
writer. If the Throwable class has a getCause
method (i.e. running on jre1.4 or higher), this method just
uses Throwable's printStackTrace() method. Otherwise, generates
the stack-trace, by taking into account the 'topDown' and
'trimStackFrames' parameters. The topDown and trimStackFrames
are set to 'true' by default (produces jre1.4-like stack trace).
Throwable throwable = this.nestable;
// if running on jre1.4 or higher, use default printStackTrace
if ( ExceptionUtils.isThrowableNested() ) {
if ( throwable instanceof Nestable ) {
( ( Nestable ) throwable ).printPartialStackTrace( out );
}
else {
throwable.printStackTrace( out );
}
return;
}
// generating the nested stack trace
List stacks = new ArrayList();
while ( throwable != null ) {
String[] st = getStackFrames( throwable );
stacks.add( st );
throwable = ExceptionUtils.getCause( throwable );
}
// If NOT topDown, reverse the stack
String separatorLine = "Caused by: ";
if ( !topDown ) {
separatorLine = "Rethrown as: ";
Collections.reverse( stacks );
}
// Remove the repeated lines in the stack
if ( trimStackFrames ) trimStackFrames( stacks );
synchronized ( out ) {
for ( Iterator iter = stacks.iterator(); iter.hasNext(); ) {
String[] st = ( String[] ) iter.next();
for ( int i = 0, len = st.length; i < len; i++ ) {
out.println( st[i] );
}
if ( iter.hasNext() ) out.print( separatorLine );
}
}
|
public void | printStackTrace()Prints the stack trace of this exception the the standar error
stream.
printStackTrace( System.err );
|
protected void | trimStackFrames(java.util.List stacks)Trims the stack frames. The first set is left untouched. The rest
of the frames are truncated from the bottom by comparing with
one just on top.
for ( int size = stacks.size(), i = size - 1; i > 0; i-- ) {
String[] curr = ( String[] ) stacks.get( i );
String[] next = ( String[] ) stacks.get( i - 1 );
List currList = new ArrayList( Arrays.asList( curr ) );
List nextList = new ArrayList( Arrays.asList( next ) );
ExceptionUtils.removeCommonFrames( currList, nextList );
int trimmed = curr.length - currList.size();
if ( trimmed > 0 ) {
currList.add( "\t... " + trimmed + " more" );
stacks.set( i,
currList.toArray( new String[currList.size()] ) );
}
}
|