The author's claim, from what I undestand it to be, is that methods should not require Try..Catch blocks to check conditional
requirements known to the calling method. I very much disagree.
The author states that "if a method has specified some pre-condition then the failure of that condition is the responsibility of the
client of the method". In programming terms, from my understanding of the author's statement, this means that a methods failure
depends on the caller's ability to check for conditions, and assure them to be correct, prior to the calling of the method.
This is the sole purpose of documentation
The author did not explain what actions the caller should take if it cannot satisfy these conditions. It seems to be assumed that
the caller will be able to gracefully handle "failure".
Quote: "The client *should* do whatever is necessary to ensure it will meet the pre-conditions. It may do runtime tests or it may
assume some condition is satisfied based on its own specification"
The problem with this is that the method may have to first check internal state before adjusting the "condition", in which case the
caller will not be able to do "whatever is necessary". Furthermore, methods and "encaspulation" teach us that reusability produces
less clutter and code-bloat. If the call-stack is bloated due to runtime-checking of "conditions", well that's just business logic
coded incorrectly. Maybe the implemenation should be thought out more effeciently.
Anyway, in .NET I've never heard of the performance of an application hinging on the size of the call stack.
It seems the author is not using Exceptions as they are intended in the .NET framework. Exceptions are meant for cases where an
application (or method) cannot gracefully handle invalid conditions. Documentation provides a means for coding against methods to
insure these conditions are met prior to calling a method. If an exception is thrown, the code should be rewritten to do
runtime-checks before calling the exception-throwing method.
This is called a bug. An overlooked exception that could be handled gracefully.
If CustomType is your object, and Parse is your method (meaning that you have the ability to change the implementation), then I
would use a Try...Catch block and throw an ArgumentException when an invalid input parameter has been passed to the method.
Implement a method like "IsValid" to do a runtime check first if your concerned about the ArgumentException being thrown. After
all, it's an "exception" to your code, something that has not been accounted for.
No user wants to see a Debug.Asser popup while running there application. This is for debug use only on a development and testing
platform.
I hope I've cleared it up (and didn't offend anyone)
GL