code: private String getStackTrace(final Throwable exception) {
  
          if (exception != null) {
  
              StringBuilder sb = new StringBuilder();
  
              StackTraceElement[] stackTrace = exception.getStackTrace();
              for (StackTraceElement element : stackTrace) {
                  sb.append(element.toString());
                  sb.append('\n');
              }
  
              if (exception.getCause() != null) {
  
                  StackTraceElement[] stackTraceCause = exception.getCause().getStackTrace();
                  for (StackTraceElement element : stackTraceCause) {
                      sb.append(element.toString());
                      sb.append('\n');
                  }
  
              }
  
              return sb.toString();
          }
  
          return null;
      }
docs: Gets stacktrace as a String.
  
  @param exception Exception for which the stacktrace should be returned.
  @return Stacktrace as a String.