【发布时间】:2015-07-17 18:09:46
【问题描述】:
在正常的try-catch-finally中,像这样,
try {
throw new ExceptionA();
} finally {
throw new ExceptionB();
}
ExceptionA 在 Exception B 之前被抛出。ExceptionA 将被抑制。
但是在try-with-resource中,像这样,
try ( // declare resource that throw ExceptionA in close method ) {
throw new ExceptionB();
}
ExceptionA 在 ExceptionB 之后抛出。 ExceptionA 将被抑制。
为什么它们有不同的异常抑制顺序?
【问题讨论】:
标签: java exception exception-handling try-with-resources