تخطَّ إلى المحتوى

Catch Of Control Flow Exception (ARCH4168)

هذا المحتوى غير متوفر بلغتك بعد.

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.

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// ignore
}
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.