code: public static String getStacktrace(Throwable throwable) {
          StringWriter sw = new StringWriter();
          PrintWriter pw = new PrintWriter(sw, true);
          throwable.printStackTrace(pw);
          return sw.getBuffer().toString().trim();
      }
docs: Gets the stack trace from a Throwable as a String.
  
  <p>The result of this method vary by JDK version as this method
  uses {@link Throwable#printStackTrace(java.io.PrintWriter)}.
  On JDK1.3 and earlier, the cause exception will not be shown
  unless the specified throwable alters printStackTrace.</p>
  
  @param throwable the {@code Throwable} to be examined
  @return the stack trace as generated by the exception's
  {@code printStackTrace(PrintWriter)} method