Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

lang.RuntimeException: practical reference

lang.RuntimeException: practical reference: RuntimeException is the unchecked exception base; callers are not required to catch or declare it.

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

Syntax

java.lang.RuntimeException

RuntimeException is the unchecked exception base; callers are not required to catch or declare it.

Throw a specific RuntimeException subtype for a programming error or violated unchecked contract, and catch it only where that exact failure has a recovery policy.

Unchecked does not mean harmless: callers need not declare or catch it, and a broad catch can hide defects such as NullPointerException or IllegalStateException.

message and cause may be null, suppressed failures may be attached, and the operation can already have changed state before the exception is thrown.

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 {
        RuntimeException error = new RuntimeException("unchecked");
        System.out.println(error.getMessage());
    }
}

Result

unchecked

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

Sources