Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

lang.Error: practical reference

lang.Error: practical reference: Error is the base for serious VM or linkage conditions that applications ordinarily should not catch for recovery.

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

Syntax

java.lang.Error

Error is the base for serious VM or linkage conditions that applications ordinarily should not catch for recovery.

Treat Error as a signal of a serious VM, linkage, or invariant failure rather than an ordinary domain result.

Do not catch Error broadly: OutOfMemoryError, LinkageError, or AssertionError can leave no safe continuation path.

message and cause may be null. Recovery decisions must be made for the exact Error subtype, not the superclass.

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

Result

fatal

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

Sources