NativeMethodAccessorImpl 調(diào)用方法聲明它可以拋出 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);本機(jī)方法在某些情況下會拋出 IllegalArgumentException,例如Exception in thread "main" java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)但我沒有看到任何拋出已InvocationTargetException 檢查異常的選項可以InvocationTargetException通過本機(jī)方法拋出invoke0(不聲明異常)?或者InvocationTargetException由于方法簽名向后/未來兼容性而保留?
1 回答

慕妹3146593
TA貢獻(xiàn)1820條經(jīng)驗 獲得超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)
例如,當(dāng)找不到 FXML 資源文件時。
添加回答
舉報
0/150
提交
取消