NativeMethodAccessorImpl 调用方法声明它可以抛出 IllegalArgumentException或InvocationTargetExceptionpublic Object invoke(Object obj, Object[] args) throws IllegalArgumentException, InvocationTargetException{ // We can't inflate methods belonging to vm-anonymous classes because // that kind of class can't be referred to by name, hence can't be // found from the generated bytecode. if (++numInvocations > ReflectionFactory.inflationThreshold() && !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) { MethodAccessorImpl acc = (MethodAccessorImpl) new MethodAccessorGenerator(). generateMethod(method.getDeclaringClass(), method.getName(), method.getParameterTypes(), method.getReturnType(), method.getExceptionTypes(), method.getModifiers()); parent.setDelegate(acc); } return invoke0(method, obj, args);}private static native Object invoke0(Method m, Object obj, Object[] args);本机方法在某些情况下会抛出 IllegalArgumentException,例如Exception in thread "main" java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)但我没有看到任何抛出已InvocationTargetException 检查异常的选项可以InvocationTargetException通过本机方法抛出invoke0(不声明异常)?或者InvocationTargetException由于方法签名向后/未来兼容性而保留?
1 回答
慕妹3146593
TA贡献1820条经验 获得超9个赞
invoke0可以抛出InvocationTargetException
:
Exception in Application start method java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
例如,当找不到 FXML 资源文件时。
添加回答
举报
0/150
提交
取消