Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

time.format.DateTimeParseException: practical reference

time.format.DateTimeParseException: practical reference: DateTimeParseException reports failed date/time parsing with the parsed text and an error index.

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

Syntax

java.time.format.DateTimeParseException

DateTimeParseException reports failed date/time parsing with the parsed text and an error index.

Catch DateTimeParseException at an input boundary to report invalid date-time text using its parsed string and error index without exposing unrelated internals.

The error index indicates where parsing failed, not necessarily the semantic root cause, and message wording is diagnostic rather than a stable interface. The class is intended for single-thread use.

The stored parsed text can contain sensitive input and should not be logged blindly. A cause may be present when lower-level resolution failed after lexical parsing.

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 {
        try { java.time.LocalDate.parse("2024-02-30"); } catch (java.time.format.DateTimeParseException error) { System.out.println(error.getErrorIndex()); }
    }
}

Result

0

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

Sources