Saturday, July 9, 2011

Get the printStackTrace message into a String. in java

import java.io.PrintWriter;
import java.io.StringWriter;

public class Temp {
public static void main(String args[]) {
try {
int x = 10 / 0;
} catch (Exception e) {
StringWriter writer = new StringWriter();
e.printStackTrace(new PrintWriter(writer));
String trace = writer.toString();
System.out.println(trace);
}
}

}

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More