Compile Error: Unreachable Statement

error: unreachable statement

Quick Answer

You have code after a return, throw, break, or continue statement that can never execute. Remove the dead code or restructure the control flow.

Why This Happens

Java's compiler detects code that can never be reached due to unconditional control flow transfers like return or throw. Unlike some languages, Java treats unreachable code as a compile error, not just a warning. This prevents accidental dead code.

The Problem

public int getValue() {
    return 42;
    System.out.println("done"); // Unreachable statement
}

The Fix

public int getValue() {
    System.out.println("done"); // Move before return
    return 42;
}

Step-by-Step Fix

  1. 1

    Identify the unreachable code

    The compiler error points to the exact line that is unreachable.

  2. 2

    Find the blocking statement

    Look for a return, throw, break, continue, or while(true) before the unreachable line.

  3. 3

    Remove or reorder

    Delete the dead code if it is not needed, or move it before the control flow statement.

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