code: public static String getStackTrace(final Throwable ex) {
          final StringWriter sw = new StringWriter();
          final PrintWriter pw = new PrintWriter(sw, true);
          ex.printStackTrace(pw);
          pw.flush();
          sw.flush();
          return sw.toString();
      }
docs: A standard function to get the stack trace from a
  thrown Exception
  
  @param ex The thrown exception
  @return The stack trace from the exception