Suppose I have a library that uses exceptions to indicate success or failure.
I expect the exceptions to be thrown a lot of times when I try requesting different properties of this library.
Now in .NET, it is said that trying costs nothing, but catching does. (Exception handling cost is in the exceptional case).
Is there a way to tell .NET to put the cost in installing the handler? Like in C++?
Clarifying: the calling code 'iterates' over all possible function argument values:
foreach( var enumvalue in Enum.GetValues( MyEnum ) ) {
try {
libraryObject.libFunction( enumvalue ); // will probably throw...
} catch(ArgumentException) {
}
}
Note: I know this is not a great API. It should be extended in order to iterate over the 'possible' values, or to work with return codes. I don't need answers that restate that.