code: public static String getExceptionStacktrace(Throwable t) {
          try (StringWriter errors = new StringWriter()) {
              t.printStackTrace(new PrintWriter(errors));
              return errors.toString();
          } catch (IOException e) {
              LOG.error(e);
              return null;
          }
      }
docs: get the stacktrace string.
  
  @param t the throwable object.
  @return the stacktrace string.