InterruptedException

java.lang.InterruptedException

Quick Answer

The thread was interrupted while waiting, sleeping, or blocked. Handle the interruption by either re-interrupting the thread or stopping the task.

Why This Happens

InterruptedException is thrown when a thread that is sleeping, waiting, or blocked is interrupted by another thread calling interrupt(). It is a cooperative cancellation mechanism. Swallowing this exception silently is a common mistake that makes thread cancellation unreliable.

The Problem

try {
    Thread.sleep(5000);
} catch (InterruptedException e) {
    // Swallowed! Thread interrupt status is lost
}

The Fix

try {
    Thread.sleep(5000);
} catch (InterruptedException e) {
    Thread.currentThread().interrupt(); // Restore interrupt status
    return; // Exit the task
}

Step-by-Step Fix

  1. 1

    Identify the blocking call

    Find the sleep(), wait(), join(), or blocking I/O call that threw InterruptedException.

  2. 2

    Determine the interruption source

    Find what code is calling interrupt() on this thread and why (shutdown, cancellation, timeout).

  3. 3

    Handle properly

    Either re-interrupt the thread with Thread.currentThread().interrupt() and return, or propagate the exception up the call stack.

Got the actual stack trace?

Paste it into our free AI explainer to get the cause and the fix for your specific case — no signup, nothing to install.

Explain my error

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free