InvocationTargetException
来源:互联网 发布:人工智能百度云资源 编辑:程序博客网 时间:2024/06/04 19:33
InvocationTargetException 是一种包装由调用方法或构造方法所抛出异常的受查异常。这个异常并不是Eclipse插件开发特有的,而是标准JDK中的,它定义在 java.lang.reflect包下。在进行Java开发的时候很少会接触到这个异常,不过在进行Eclipse插件开发中则不同,很多API都声明抛出此类异常,因此必须对此异常进行处理。
但是InvocationTargetException太过于宽泛,在trouble shouting的时候,不能给人非常直观的信息,所以在处理反射方法异常的时候,我们需要把这个InvocationTargetException的targetException提取处理,重新抛出,因为这个才是对我们分析程序bug真正有帮助的异常:
一般情况下我们会调用e.getMessage()或者e.printStackTrace();查看错误,但是通过查看InvocationTargetException的源码得InvocationTargetException 并没有覆盖getMessage方法,所以消息当然是空的了。我们需要调用InvocationTargetException 的getTargetException方法得到要被包装的异常,这个异常才是真正我们需要的异常。
Apache Ranger的源码中是如下处理的:
try {m.invoke(null, master) ;logInfo("Execute method name [" + mname + "] in Class [" + cName + "] is successful.");} catch (InvocationTargetException e) {Throwable cause = e ;boolean tableExistsExceptionFound = false ;if (e != null) { Throwable ecause = e.getTargetException() ;if (ecause != null) {cause = ecause ;if (ecause instanceof TableExistsException) {tableExistsExceptionFound = true ;}}}
0 0
- InvocationTargetException
- InvocationTargetException
- InvocationTargetException
- InvocationTargetException
- InvocationTargetException
- 关于InvocationTargetException
- InvocationTargetException异常
- InvocationTargetException 浅析
- InvocationTargetException异常
- InvocationTargetException解决。
- InvocationTargetException错误
- InvocationTargetException原因分析
- java mail InvocationTargetException
- java.lang.reflect.InvocationTargetException
- java.lang.reflect.InvocationTargetException
- eclipse axis2 reflect.invocationtargetexception
- java.lang.reflect.InvocationTargetException
- InvocationTargetException导致NullPointerException
- MYSQL事务——四个隔离级别
- Android中使用WebView加载H5页面的方法
- 什么是OOM?如何解决OOM问题!
- ContentResolver读取音乐文件
- Linux 加,减,乘,除
- InvocationTargetException
- LeetCode——001
- 如何才能取到没有在.h文件中声明,但在.m文件中实现的方法
- 分享一个链接
- 关于进程页表内核部分和内核主页表的关系(Linux 2.6.11)
- java要整理的一些知识
- maven两个错误的解决方式
- AOAPC:Chapter1Example2 (UVa 11729)
- .net / C#程序读取MAC地址的几种方法