Re: We do not use C++ exceptions
On Feb 7, 7:42 pm, Thant Tessman <thant.tess...@gmail.com> wrote:
Here is the nub of the matter. I posit that placing obligations on the
caller is almost always something to be avoided if failing to meet those
obligations results in undefined behavior. And asserts don't eliminate
undefined behavior.
That much is clear, but the "input validation" style arguments you
cited do not, in my opinion, provide any support for this claim. Bad
input simply is not allowed to trickle down to the basic building
blocks such as stack::pop and vector::operator[] in a well-designed
program, and a logic error that causes an attempt to pop an item from
an empty stack rarely has anything to do with bad input on the program
level.
Or, to illustrate the matter with an example, is this:
$ eval 1+2
Assertion failed: !data_.empty()
Segmentation fault, core dumped
$
worse than this:
$ eval 1+2
Exception: attempted pop from an empty stack
$
?
The exceptionist says that it obviously is, because the second program
is more robust. The assertionist says that both programs are broken,
and that instead of making a broken program more robust, we should
spend our resources toward this goal:
$ eval 1+2
3
$
because lack of brokenness dominates robustness.
I also posit that a well-designed language will help
allow the author of a function to avoid placing obligations on the caller.
This is true.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]