Created
April 5, 2016 12:07
-
-
Save Fifan31/bbb4f57f2e63fe80b7a10f71c721093f to your computer and use it in GitHub Desktop.
Convert exception stacktrace to String object
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
/** | |
* 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