C#: Exception to throw when a certain type was expected
- by cbp
I know this sort of code is not best practice, but nevertheless in certain situations I find it is a simpler solution:
if (obj.Foo is Xxxx)
{
// Do something
}
else if (obj.Foo is Yyyy)
{
// Do something
}
else
{
throw new Exception("Type " + obj.Foo.GetType() + " is not handled.");
}
Anyone know if there is a built-in exception I can throw in this case?