Re:Real cost of C++ exception vs error-code checking
by wlievens on Tuesday March 08, 2011 @03:18PM
(#2302432)
That's a precondition check. While useful (essential), it doesn't cover all "forgot to check an error code" cases.
Re:Real cost of C++ exception vs error-code checking
by davidsiems on Tuesday March 08, 2011 @04:01PM
(#2302577)
If you're really trying to write efficient code (which is what this article claims to care about) you don't 'forget' to do things like assert that the data is correct. You _guarantee_ that the data is correct and then you process it as fast as you can without having to check.
You only run into trouble with this method if the data verification step is the computationally expensive operation.
Just to finish out the example to show how much cleaner asserting is compared to error handling:
That's not to say that error handling doesn't have its place, but it should only be used for data that you can't anticipate.