C#: Exception to throw when a certain type was expected

Posted by cbp on Stack Overflow See other posts from Stack Overflow or by cbp
Published on 2010-04-01T01:40:51Z Indexed on 2010/04/01 1:43 UTC
Read the original article Hit count: 362

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about exceptions