【发布时间】:2010-09-09 03:51:27
【问题描述】:
有没有办法从 finally 子句中检测到异常正在被抛出?
请看下面的例子:
try {
// code that may or may not throw an exception
} finally {
SomeCleanupFunctionThatThrows();
// if currently executing an exception, exit the program,
// otherwise just let the exception thrown by the function
// above propagate
}
或者你唯一能做的就是忽略其中一个例外?
在 C++ 中,它甚至不允许您忽略其中一个异常,而只是调用 terminate()。大多数其他语言使用与 java 相同的规则。
【问题讨论】:
标签: java exception fault-tolerance