allow controllable stack dump in ExceptionUtil.java

This commit is contained in:
Kelven Yang 2011-03-29 14:03:53 -07:00
parent 7ce9845fb7
commit 6ff40b7e88

View File

@ -22,12 +22,19 @@ import java.io.StringWriter;
public class ExceptionUtil {
public static String toString(Throwable th) {
return toString(th, true);
}
public static String toString(Throwable th, boolean printStack) {
final StringWriter writer = new StringWriter();
writer.append("Exception: " + th.getClass().getName() + "\n");
writer.append("Message: ");
writer.append(th.getMessage());
writer.append("\n Stack: ");
th.printStackTrace(new PrintWriter(writer));
writer.append(th.getMessage()).append("\n");
if(printStack) {
writer.append("Stack: ");
th.printStackTrace(new PrintWriter(writer));
}
return writer.toString();
}
}