This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String stackTraceToString(Throwable e) | |
{ | |
StringBuilder sb = new StringBuilder(); | |
for (StackTraceElement element : e.getStackTrace()) | |
{ | |
sb.append(element.toString()); | |
sb.append("\n"); | |
} | |
return sb.toString(); | |
} |
For that, you should look at:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String stackTraceToString(Throwable e) | |
{ | |
StringWriter sw = new StringWriter(); | |
PrintWriter pw = new PrintWriter(sw); | |
e.printStackTrace(pw); | |
return sw.toString(); | |
} |
Just thought I'd write this down here, I always forget how to do it.
References
- [1] How can I convert a stack trace to a string?
- http://stackoverflow.com/questions/1149703/how-can-i-convert-a-stack-trace-to-a-string
No comments:
Post a Comment