What is the easiest way to convert the result of Throwable.getStackTrace() to a string that depicts the stacktrace?
Throwable.getStackTrace()
Use Throwable.printStackTrace(PrintWriter pw) to send the stack trace to an appropriate writer.
Throwable.printStackTrace(PrintWriter pw)
import java.io.StringWriter; import java.io.PrintWriter; // ... StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); String sStackTrace = sw.toString(); // stack trace as a string System.out.println(sStackTrace);
1.4m articles
1.4m replys
5 comments
56.9k users