【发布时间】:2013-11-29 11:43:57
【问题描述】:
在下面的代码sn-p中,如果ex1被抛出,会被第二个catch块捕获,还是会被扔回给方法的调用者?
如果将其抛回给调用者,然后在 finally 块(ex2)中发生第二个异常,是否意味着将有 2 个异常被抛回给调用者(ex1 和 ex2)?
try {
// write to file
} catch (IOException ex1) {
throw ex1;
} finally {
try {
aBufferedWriter.close();
} catch (IOException ex2) {
throw ex2;
}
}
【问题讨论】:
-
如果你只是重新抛出异常,那么捕获它是没有意义的。
-
为什么当你把它扔进你的渔获物时,你甚至会抓住它?