gpt4 book ai didi

java - 为什么我们不能在 Runnable 中重新抛出 InterruptedException?

转载 作者:行者123 更新时间:2023-12-01 21:15:29 25 4
gpt4 key购买 nike

从下面的文章中,它说“至少,每当您捕获 InterruptedException 并且不重新抛出它时,在返回之前重新中断当前线程。”。

我的问题是为什么不重新抛出 InterruptedException 或无法从 Runnable 重新抛出它? http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html

最佳答案

因为你不能。 InterruptedException 是一个已检查异常,未声明由 Runnable.run() 引发。出于同样的原因,您不能只修改方法签名。

关于java - 为什么我们不能在 Runnable 中重新抛出 InterruptedException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40258904/

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