public IPredefinedInterface
{
void DoSomething(Object obj);
}
public class MyClass<T> : IPredefinedInterface
{
public void DoSomething(Object obj)
{
if (!(obj is T)) throw new ???
SomeOtherFunc((T)obj);
}
}
Not sure what the appropriate exception here is... ArgumentException, InvalidCastException, etc?
It's a problem with the argument, so ArgumentException. You haven't actually done the cast, so InvalidCastException is not appropriate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With