gpt4 book ai didi

java - 如果try block 中有 "Where (true)" block ,是否会到达finally block ?

转载 作者:行者123 更新时间:2023-12-01 07:03:41 28 4
gpt4 key购买 nike

这是令我困惑的代码:

public Integer getInteger(BlockingQueue<Integer> queue) {
boolean interrupted = false;
try {
while (true) {
try {
return queue.take();
} catch (InterruptedException e) {
interrupted = true;
// fall through and retry
}
}
} finally {
if (interrupted)
Thread.currentThread().interrupt();
}
}

看起来try block 不会因为While(true) block 而停止,但我被告知finally block 总是在try block 结束后执行。那么finally block 什么时候执行呢?

最佳答案

当存在另一个不是从 InterruptedException 派生的异常时

关于java - 如果try block 中有 "Where (true)" block ,是否会到达finally block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33272246/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com