code: public int getStackTraceDepth(Throwable throwable) {
      try {
        return (int) (Integer) getDepthMethod.invoke(javaLangAccess, throwable);
      } catch (InvocationTargetException e) {
        // There really should be no chance of runtime errors.
        if (e.getCause() instanceof RuntimeException) {
          throw (RuntimeException) e.getCause();
        } else if (e.getCause() instanceof Error) {
          throw (Error) e.getCause();
        }
        // This should not be possible because the getStackTraceElement() method does not declare
        // any checked exceptions (though APIs may change over time).
        throw new RuntimeException(e.getCause());
      } catch (IllegalAccessException e) {
        // This should never happen because the method has been successfully invoked once already.
        throw new AssertionError(e);
      }
    }
docs: Mimics a direct call to {@code getStackTraceDepth()} on the JavaLangAccess interface without
  requiring the Java runtime to directly reference the method (which may not exist on some
  JVMs).