Skip to content

Instantly share code, notes, and snippets.

@Fifan31
Created April 5, 2016 12:07
Show Gist options
  • Select an option

  • Save Fifan31/bbb4f57f2e63fe80b7a10f71c721093f to your computer and use it in GitHub Desktop.

Select an option

Save Fifan31/bbb4f57f2e63fe80b7a10f71c721093f to your computer and use it in GitHub Desktop.

Revisions

  1. Fifan31 created this gist Apr 5, 2016.
    14 changes: 14 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    /**
    * 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();
    }