tags:

views:

72

answers:

3

Wondering what is the most appropiate Exception to throw when there is some case where I get an implementation of in interface that I dont expect

Is there such a thing as UnsupportedTypeException in .net that I m not aware of? Cheers

+3  A: 

NotSupportedException exists that may be what you want to consider.

JB King
+3  A: 

What is not supported? When its not supported, why does your funtion takes it as parameter? This is not good design, because the workflow relays on Exceptions and can result in unpredictable behaviour in future. One alternative would be to overload such functions and be more specific with the given types. When you are sure that this type should not yet be used but will be supported in foreseeable time, you could throw a NotSupportedException with an understandable Errormessage.

Tim Schmelter
I find it very difficult to judge a design without more information, there are many cases where something would work in one implementation and not in another. However, you are right in saying that an exception should not be part of the normal flow but I don't think this is the case in this instance...It is more of a indication to the programmer than to control the flow IMHO, obviously, if it is not supported, stop doing it. :)
Joel Gauvreau