Package Summary Overview Summary

Module java.base
Package java.lang

# Class MatchException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
java.lang.MatchException

All Implemented Interfaces:
  `Serializable`

public 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 match target that does not match any of the provided patterns at runtime. This can currently arise from the following case:

- 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.

Since:
  19
See Also:
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MatchException()`
  Constructs an `MatchException` with no detail message.
  `MatchException (String message)`
  Constructs an `MatchException` with the specified detail message.
  `MatchException (String message, Throwable cause)`
  Constructs an `MatchException` with the specified detail message and cause.
  `MatchException (Throwable cause)`
  Constructs an `MatchException` with the specified cause.

- ## Method Summary

  ### Methods declared in class java.lang.Throwable

  `addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString`

  ### Methods declared in class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### MatchException

    public MatchException()
    Constructs an `MatchException` with no detail message.

  - ### MatchException

    public MatchException (String message)
    Constructs an `MatchException` with the specified detail message.
    Parameters:
      `message` - the detail message (which is saved for later retrieval by the `Throwable.getMessage()` method).

  - ### MatchException

    public MatchException (Throwable cause)
    Constructs an `MatchException` with the specified cause.
    Parameters:
      `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.)

  - ### 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.)