title: Correct exception to throw for an unhandled switch case for an argument?
body: <p><strong>NOTE</strong>: This is different than the proposed duplicates as this deals with an argument rather than a value. The behavior and applicable scenarios are essentially different.</p>
  <p>Say we have <code>SomeEnum</code> and have a switch statement handling it like:</p>
  <pre class="lang-cs prettyprint-override"><code>enum SomeEnum
  {
      One,
      Two,
  }
  
  void someFunc(SomeEnum value)
  {
      switch(value)
      {
          case SomeEnum.One:
              ...
              break;
          case SomeEnum.Two:
              ... 
              break;
          default:
              throw new ??????Exception(&quot;Unhandled value: &quot; + value.ToString());    
      }
  }
  </code></pre>
  <p>As you see we handle all possible enum values but still keep a default throwing an exception in case a new member gets added and we want to make sure we are aware of the missing handling.</p>
  <p>My question is: what's the right exception in such circumstances where you want to notify that the given code path is not handled/implemented or should have never been visited? We used to use <code>NotImplementedException</code> but it doesn't seem to be the right fit. Our next candidate is <code>InvalidOperationException</code> but the term doesn't sound right. What's the right one and why?</p>
  <p><strong>EDIT</strong>: C# 8.0 introduced <a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/switch-expression" rel="nofollow noreferrer">switch expressions</a> which produce compiler warnings for non-exahustive switch statements. That's another reason why you should use switch expressions over switch statements whenever applicable. The same function can be written in a safer way like:</p>
  <pre class="lang-cs prettyprint-override"><code>void someFunc(SomeEnum value)
  {
      _ = value switch
      {
          SomeEnum.One =&gt; ....,
          SomeEnum.Two =&gt; ...., 
      }
  }
  </code></pre>
  <p>When a new member gets added to <code>SomeEnum</code>, the compiler will show the warning <em>&quot;CS8509: The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern 'EnumHandling.SomeEnum.Three' is not covered.&quot;</em> for the switch expression which makes it way easier to catch potential bugs.</p>