code: public static String dumpStack(final Throwable cause) {
          if (cause == null) {
              return "Throwable was null";
          }
          final StringWriter sw = new StringWriter();
          final PrintWriter s = new PrintWriter(sw);
  
          // This is very close to what Thread.dumpStack does.
          cause.printStackTrace(s);
  
          final String stack = sw.toString();
          try {
              sw.close();
          } catch (final IOException e) {
              LOG.warn("Could not close writer", e);
          }
          s.close();
          return stack;
      }
docs: Returns the stack trace as a string.
  
  @param cause
  The thread to dump.
  @return The stack trace as a string.