Catch Of Control Flow Exception (ARCH4168)
Esta página aún no está disponible en tu idioma.
Key java.logging.swallow-interrupted-exception · Severity warning · Category logging
Catching and swallowing cancellation/control exceptions such as InterruptedException discards the thread’s interrupt status and breaks the cancellation mechanism. These exceptions must be allowed to propagate or the interrupt flag must be restored.
Incorrect
Section titled “Incorrect”try { Thread.sleep(1000);} catch (InterruptedException e) { // ignore}Correct
Section titled “Correct”try { Thread.sleep(1000);} catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new CancellationException("Operation interrupted");}When InterruptedException is caught, restore the interrupt flag with Thread.currentThread().interrupt() and terminate the operation.