Created
June 29, 2012 11:47
-
-
Save jmorenoamor/3017520 to your computer and use it in GitHub Desktop.
Stack trace to String
This file contains hidden or 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
// Inline | |
StringWriter sw = new StringWriter(); | |
e.printStackTrace(new PrintWriter(sw)); | |
String exceptionAsStrting = sw.toString(); | |
// Function | |
public String stackTraceToString(Throwable e) | |
{ | |
StringBuilder sb = new StringBuilder(); | |
for (StackTraceElement element : e.getStackTrace()) | |
{ | |
sb.append(element.toString() + "\n"); | |
} | |
return sb.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment