Skip to content

Instantly share code, notes, and snippets.

@Fifan31
Created April 5, 2016 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Fifan31/bbb4f57f2e63fe80b7a10f71c721093f to your computer and use it in GitHub Desktop.
Save Fifan31/bbb4f57f2e63fe80b7a10f71c721093f to your computer and use it in GitHub Desktop.
Convert exception stacktrace to String object
/**
* Creates and returns a {@link java.lang.String} from <code>t</code>’s stacktrace
* @param t Throwable whose stack trace is required
* @return String representing the stack trace of the exception
*/
public String getStackTrace(Throwable t) {
StringWriter stringWritter = new StringWriter();
PrintWriter printWritter = new PrintWriter(stringWritter, true);
t.printStackTrace(printWritter);
printWritter.flush();
stringWritter.flush();
return stringWritter.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment