【发布时间】:2013-07-12 05:30:34
【问题描述】:
当 FileNotFoundException 被 IOException 覆盖时,捕获 FileNotFound 和 IOException 的目的是什么?
例子:
try {
pref.load(new FileInputStream(file.getAbsolutePath()));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
相对于:
try {
pref.load(new FileInputStream(file.getAbsolutePath()));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
是否只是在抛出 FileNotFoundException 时启用不同的代码来执行?还是有别的原因?
编辑:有哪些可以抛出 IOException 的示例? (除了 FileNotFoundException)
【问题讨论】:
-
“如果抛出 FileNotFoundException,是否只是为了让不同的代码能够被执行?” 是!!!
标签: java try-catch ioexception filenotfoundexception