exception java.io.IOException is never thrown in body of corresponding try statement是怎么回事??

hard_blue 2005-04-27 05:19:48
ComplexV3JspBuilder(String fileName) {
builder = new SAXBuilder();
try {
doc = builder.build(new File(fileName));
Element root = doc.getRootElement();
programName = root.getAttributeValue("id");
} catch (JDOMException e) {
System.err.println("xml is not well-formed.");
e.printStackTrace();
} catch (IOException e) {
System.err.println("IO error");
e.printStackTrace();
}
init();
}

编译的时候第二个catch有错
错误提示:exception java.io.IOException is never thrown in body of corresponding try statement
请问怎么回事
...全文
4340 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
MARS.nEIL 2005-04-27
  • 打赏
  • 举报
回复
若方法builder.build没有甩出异常,就不用对异常进行处理..把try...catch去掉.
shan1119 2005-04-27
  • 打赏
  • 举报
回复
同意楼上两位大哥
jFresH_MaN 2005-04-27
  • 打赏
  • 举报
回复
很清楚了,去掉这些
catch (IOException e) {
System.err.println("IO error");
e.printStackTrace();
}
silverend 2005-04-27
  • 打赏
  • 举报
回复
try {
doc = builder.build(new File(fileName));
Element root = doc.getRootElement();
programName = root.getAttributeValue("id");
}

字面上好象是说在该try语句块内永不会抛出java.io.IOException ,
将catch (IOException e) {
System.err.println("IO error");
e.printStackTrace();
}
删除试试

62,616

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧