InvocableTargetException 内部的回避原因
执行 Java 代码时,我捕获了 InitationTargetException。使用 printStackTrace 方法,我得到以下信息:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at Tester.main(Tester.java:180)
Caused by: java.lang.NullPointerException
at [...] (it doesn't really matters)
我的代码检查了其他人编写的多个程序,因此 printStackTrace 显示的原因各不相同。但是,如果我尝试使用 getCause 方法仅获取内部原因,结果总是令人厌恶的 null!
Java 6 API 表示,从版本 1.4 开始,getCause 返回构造期间提供的原因异常...我应该假设 Method.invoke 没有正确构造异常,还是我丢失了一些东西?
提前致谢
Executing a Java code I capture an InvocationTargetException. Using the printStackTrace method I get the following:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at Tester.main(Tester.java:180)
Caused by: java.lang.NullPointerException
at [...] (it doesn't really matters)
My code checks several programs written by other persons, so the cause shown by printStackTrace is varied. However, if I try to get just the internal cause using method getCause, the result is always a disgusting null!
Java 6 API says that, from release 1.4 in advance, getCause returns the cause exception provided during construction... should I assume that Method.invoke does not construct the exception properly, or am I losing something?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论