Top Description Fields Constructors
java.lang

public final Class MatchException

extends RuntimeException
Class Inheritance

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 specified patterns at run time, even though the construct has been deemed exhaustive. This is intentional and can arise from a number of cases:

MatchException may also be thrown by the process of pattern matching a value against a pattern. For example, pattern matching involving a record pattern may require accessor methods to be implicitly invoked in order to extract the component values. If any of these accessor methods throws an exception, pattern matching completes abruptly and throws MatchException. The original exception will be set as a cause of the MatchException. No suppressed exceptions will be recorded.

Since
21
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

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
public
MatchException(String
the detail message (which is saved for later retrieval by the getMessage() method).
message
,
Throwable
the cause (which is saved for later retrieval by the getCause() method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
cause
)

Constructs an MatchException with the specified detail message and cause.

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.lang.RuntimeException.serialVersionUID.

Annotations
@Serial

Constructor Detail

MatchExceptionback to summary
public MatchException(String message, Throwable cause)

Constructs an MatchException with the specified detail message and cause.

Parameters
message:String

the detail message (which is saved for later retrieval by the getMessage() method).

cause:Throwable

the cause (which is saved for later retrieval by the getCause() method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)