-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Runtime
Milestone
Description
Rationale
In order to facilitate the language feature at dotnet/csharplang#45, which has been approved by the LDM and mostly implemented, we should add the exception MatchFailureException to the framework. This exception is to be thrown when no branch of a pattern-matching switch expression matches the input at runtime.
Proposal
namespace System
{
/// <summary>
/// Indicates that a switch expression that was non-exhaustive failed to match its input
/// at runtime, e.g. in the C# 8 expression <code>3 switch { 4 => 5 }</code>.
/// The exception optionally contains an object representing the unmatched value.
/// </summary>
[System.Runtime.InteropServices.ComVisible(true)]
[Serializable]
public class MatchFailureException : InvalidOperationException
{
public MatchFailureException();
public MatchFailureException(object unmatchedValue);
public object UnmatchedValue { get; }
[System.Security.SecurityCritical]
public override void GetObjectData(SerializationInfo info, StreamingContext context);
}
}See also dotnet/roslyn#27747
/cc @jcouv @jaredpar
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Runtime