10
I am curious how would you maintain your code once you throw a System.ComponentModel.InvalidEnumArgumentException.
Basically I have a switch statement like this:
switch (enumValue)
{
case MyEnum.Value1:
break;
case MyEnum.Value2:
break;
default:
throw new InvalidEnumArgumentException();
}
What if I decide to add more values to MyEnum in the future, for example, Value3 and Value4? That would mean I would end up throwing a misleading exception. How would I prevent this?
Should I use reflection before throwing? What exception should I throw in this case? I'm looking for suggestions.
I just discovered this exception a couple minutes ago so maybe I am looking at this in the wrong context. Is this exception thrown when a certain enum argument is not supported (in which case Value3 and Value4 would not be supported)?