InvocationTargetException
来源:互联网 发布:apache的虚拟主机 编辑:程序博客网 时间:2024/05/16 00:25
InvocationTargetException是一种包装由调用方法或构造方法所抛出异常的受查异常。这个异常并不是Eclipse插件开发特有的,而是标准JDK中的,它定义在 java.lang.reflect包下。在进行Java开发的时候很少会接触到这个异常,不过在进行Eclipse插件开发中则不同,很多API都声明抛出此类异常,因此必须对此异常进行处理。
例如,我们开发一个方法用来统一处理异常:
private static voidhandleException(Exception e)
{
MessageDialog.openError(Activator.getDefault().getWorkbench()
.getDisplay().getActiveShell(), "error", e.getMessage());
e.printStackTrace();
}
我们发现当传递来的参数e为InvocationTargetException的时候弹出的对话框中的消息是空的,查看InvocationTargetException的源码得知InvocationTargetException并没有覆盖getMessage方法,所以消息当然是空的了。我们需要调用InvocationTargetException的getTargetException方法得到要被包装的异常,这个异常才是真正我们需要的异常。修改代码如下所示:
private static voidhandleException(Exception e)
{
String msg = null;
if (e instanceofInvocationTargetException)
{
Throwable targetEx =((InvocationTargetException) e)
.getTargetException();
if (targetEx != null)
{
msg =targetEx.getMessage();
}
} else
{
msg = e.getMessage();
}
MessageDialog.openError(Activator.getDefault().getWorkbench()
.getDisplay().getActiveShell(), "error", msg);
e.printStackTrace();
}
- 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
- 一些技术大牛的博客集锦(转)
- .NET平台
- CoreDate入门
- 关于数组操作的tips
- windows系统下Python环境的搭建
- InvocationTargetException
- Android ViewPager图片适配
- 如何快速截取某段时间内的日志
- listview的item中含有button导致onitemclick事件失效的解决方法
- IO_ Java文件操作大全
- iOS Mantle解析框架简单的使用入门(字典映射model)
- iOS-BLE蓝牙开发持续更新
- QT下面的中文乱码问题
- Android的开发框架学习分析