Module java.base
Package java.lang

Class MatchException

All Implemented Interfaces:
Serializable

public final class MatchException extends RuntimeException
MatchException is a preview API of the Java platform.
Programs can only use MatchException when preview features are enabled.
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 Details

    • MatchException

      public MatchException(String message, Throwable cause)
      Constructs an MatchException with the specified detail message and cause.
      Parameters:
      message - the detail message (which is saved for later retrieval by the Throwable.getMessage() method).
      cause - the cause (which is saved for later retrieval by the Throwable.getCause() method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)