Skip to content

Instantly share code, notes, and snippets.

@jmorenoamor
Created June 29, 2012 11:47
Show Gist options
  • Save jmorenoamor/3017520 to your computer and use it in GitHub Desktop.
Save jmorenoamor/3017520 to your computer and use it in GitHub Desktop.
Stack trace to String
// 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