code: public static void trimStackTraceTo(Throwable t, Class<?> cls) {
      StackTraceElement[] ste = t.getStackTrace();
      String name = cls.getName();
      for (int i = 0; i < ste.length; i++) {
        if (ste[i].getClassName().equals(name)) {
          t.setStackTrace(Arrays.copyOf(ste, i));
          return;
        }
      }
    }
docs: Trims the stack trace of the throwable such that the top item points at {@code cls}.