On 05/11/2025 11:10, Pavel Rappo wrote:
I've seen code that wraps InterruptedException in some other exception
prior to throwing that other exception; for example:
catch (InterruptedException e) {
throw new IOException(e);
}
I wonder if there are any legitimate cases for this, because I cannot
think of any. In my mind, it's always InterruptedException itself that
should be thrown; and if it cannot be done, then the interrupted
status should be set.
Right, if you catch InterruptedException then you should re-throw it, or
reset the interrupted status if continuing or throwing a different
exception. As it happens, I am hoping to adding "Thread Interruption"
section to the Thread class description that includes guidance on this,
and also gives us a place to link to from other parts of the API docs.
Work in progress [1], not a PR as it's ready for review.
-Alan
[1]
https://github.com/openjdk/jdk/compare/master...AlanBateman:jdk:JDK-8371226