/ Published in: Java
URL: http://www.javapractices.com/topic/TopicAction.do?Id=78
Expand |
Embed | Plain Text
import java.io.*; /** * Simple utilities to return the stack trace of an * exception as a String. */ public final class StackTraceUtil { aThrowable.printStackTrace(printWriter); return result.toString(); } /** * Defines a custom format for the stack trace as String. */ //add the class name and any message passed to constructor final StringBuilder result = new StringBuilder( "BOO-BOO: " ); result.append(aThrowable.toString()); result.append(NEW_LINE); //add each element of the stack trace for (StackTraceElement element : aThrowable.getStackTrace() ){ result.append( element ); result.append( NEW_LINE ); } return result.toString(); } /** Demonstrate output. */ } }
You need to login to post a comment.
