您的位置:首页 > 其它

反射调用方法时抛出的异常的获取

2011-09-05 15:09 344 查看
 
在反射中,调用method.invoke方法抛出的异常,会包装成InvocationTargetException,必须通过e.getTargetException(),

取出来。。

 

  try {

   testMethod = ExecuteApi.class.getMethod(testApiName, String.class);

//ExecuteApi不能是别的类,String.class是参数的类型

   testMethod.invoke(executeApi, absPathForFile);

// executeApi是实例,如果是静态,则可以直接填入参数null

  } catch (InvocationTargetException e) {

   Assert.assertTrue(TaskCheck.judageException(e.getTargetException(),

     PathNotFoundException.class));

  }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  null
相关文章推荐