【发布时间】:2012-04-25 01:25:32
【问题描述】:
考虑下面的代码,如果catch子句抛出异常,finally是否仍然运行?
try {
//code here throws exception
}
catch(Exception ex) {
//code catches above exception however code here also throws another exception
}
finally {
//does this code even run considering the exception thrown in the above catch clause??
}
【问题讨论】:
-
在我看来,您可以用一两行代码替换问题中的 cmets,然后自己进行测试。你会更快地得到答案,并且在这个过程中可能会学到一两件额外的东西。 :)
-
是的,this answer 重复并出色地回答了“finally 和 no finally 之间的区别是什么?”