code: public static String getFilteredStackTrace(Throwable t, int ref) {
  
          StringWriter sw = new StringWriter();
          FilterWriter filterWriter = new StackTraceFilterWriter(sw);
  
          printStackTrace(t, filterWriter, ref);
  
          return sw.getBuffer().toString();
      }
docs: Filter stack trace by selecting the {@link Throwable} using a reference position. Intermediate throwables will be printed
  with just their header.
  
  @param t the throwable
  @param ref throwable reference position, see {@link #getThrowable(List, int)}.
  @return String containing the stack trace.
  @since 1.11.1