On throwing InterruptedException

David Holmes david.holmes at oracle.com
Mon Nov 17 00:34:03 UTC 2025


On 6/11/2025 7:37 pm, Alan Bateman wrote:
> On 05/11/2025 14:00, Remi Forax wrote:
>> :
>>
>> If a thread is interrupted, it should stop ASAP.
>> So if you catch InterruptedException and rethrow a new exception, this 
>> should be okay (as Alan said).
> Rethrowing the InterruptedException is okay. Throwing a new exception 
> that is not an InterruptedException is okay too but only after restoring 
> the interrupted status, otherwise the thread might block again is some 
> catch block as it unwinds.

I would qualify the "restoring the interrupted status" part as it all 
depends on the overall context. If converting the IE to some other 
exception is part of the cancellation behaviour for this API then it may 
not be necessary to restore the interrupted status because the user of 
the API already knows this aspect of the computation has been cancelled. 
That cancellation request (the interrupt) may not apply to anything 
higher in the call-chain. Which is IIRC exactly how FutureTask 
cancellation operates.

David
> -Alan



More information about the core-libs-dev mailing list