java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
java.lang.MatchException
- All Implemented Interfaces:
Serializable
MatchException
is a preview API of the Java platform.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
Thrown to indicate an unexpected failure in pattern matching.
MatchException
may be thrown when an exhaustive pattern matching language construct
(such as a switch expression) encounters a value that does not match any of the provided
patterns at runtime. This can currently arise for separate compilation anomalies,
where a sealed interface has a different set of permitted subtypes at runtime than
it had at compilation time, an enum has a different set of constants at runtime than
it had at compilation time, or the type hierarchy has changed in incompatible ways between
compile time and run time.- See Java Language Specification:
-
14.11.3 Execution of a switch Statement
14.30.2 Pattern Matching
15.28.2 Run-Time Evaluation of switch Expressions - Since:
- 19
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionMatchException
(String message, Throwable cause) Constructs anMatchException
with the specified detail message and cause. -
Method Summary
Methods declared in class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
MatchException
Constructs anMatchException
with the specified detail message and cause.- Parameters:
message
- the detail message (which is saved for later retrieval by theThrowable.getMessage()
method).cause
- the cause (which is saved for later retrieval by theThrowable.getCause()
method). (Anull
value is permitted, and indicates that the cause is nonexistent or unknown.)
-
MatchException
when preview features are enabled.