code: static String stackTraceToString(Throwable th) {
          StringWriter sw = new StringWriter();
          PrintWriter pw = new PrintWriter(sw);
          for (int depth = 0; depth < 10 && th != null; depth++) {
              th.printStackTrace(pw);
              Throwable cause = th.getCause();
              if (cause != th) {
                  th = cause;
                  pw.append("-------- chained exception -------").append(nl);
              }
          }
          return sw.toString();
      }
docs: Formats an exception's stack trace as a String.
  
  @param th a throwable object (Exception or Error)
  
  @return String containing the exception's stack trace.