Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

lang.IllegalStateException: practical reference

lang.IllegalStateException: practical reference: IllegalStateException signals that a call is invalid for the receiver's current state rather than merely for an argument value.

Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime

Syntax

java.lang.IllegalStateException

IllegalStateException signals that a call is invalid for the receiver's current state rather than merely for an argument value.

Throw IllegalStateException when the receiver lifecycle or current state makes the call illegal.

It does not replace argument validation or fix a race; report both the required and observed state where safe.

Repeated close or start, calls before initialization, and concurrent state changes are distinct boundary cases.

The example exercises the documented element in a small deterministic program and compares exact standard output.

Examples

public class Main {
    public static void main(String[] args) throws Exception {
        var error = new IllegalStateException("state");
        System.out.println(error.getMessage());
    }
}

Result

state

The example exercises the documented element in a small deterministic program and compares exact standard output.

Sources