【发布时间】:2015-05-22 00:42:04
【问题描述】:
在 Java 8 文档中,从 Scanner 接收文件源作为参数的构造函数会抛出 FileNotFoundException。
但是看看下面的代码:
try{
sc = new Scanner("Rede.txt"); //This archive already exists
}
catch(FileNotFoundException f){
f.printStackTrace;
}
finally{
sc.close();
}
当我运行它时,我会得到类似的东西:
error:exception FileNotFoundException is never thrown in body of corresponding try statement
catch(FileNotFoundException f){
IOException 也是如此。奇怪的是,如果我扔掉 try-catch 部分,代码就会编译。
这里有什么问题?
【问题讨论】:
标签: java file exception try-catch java.util.scanner