code: public static String captureStackTrace(Throwable e) {
          StringWriter buffer = new StringWriter();
          e.printStackTrace(new PrintWriter(buffer));
          return buffer.toString();
      }
docs: Capture the full stack trace of an Exception, and return it in a String.