I am curious how you will maintain your code as soon as you throw a System.ComponentModel.InvalidEnumArgumentException .
Basically, I have a switch statement:
switch (enumValue) { case MyEnum.Value1: break; case MyEnum.Value2: break; default: throw new InvalidEnumArgumentException(); }
What if I want to add more values to MyEnum in the future, for example, Value3 and Value4 ? That would mean that I would eventually throw an erroneous exception. How can I prevent this?
Should I use reflection before throwing? What exception should I make in this case? I am looking for offers.
I just discovered this exception a couple of minutes ago, so maybe I am considering this in the wrong context. Is this exception Value3 if a specific enum argument is not supported (in this case, Value3 and Value4 not supported)?
source share