Re: Exceptions, Go to Hell!
"joe" <jc1996@att.net> wrote:
Nick Keighley wrote:
"joe" <jc1...@att.net> wrote:
<snip>
Could you give me a brief (if possible) description of what a
Bug is, since I now know it is not an error.
Are you trolling?
seems a pretty reasonable question to me. I use the terms pretty
inter-changeably.
I don't see how you could. If you consider "bug" and "error" to be the
same thing, then what do you call those things that return codes and
C++ exceptions are used for?
To borrow from Bertrand Meyer, we have three notions. The function
succeeds, the function fails do to a precondition violation, and the
function fails do to a postcondition violation. This discussion pertains
to the latter two.
A function can easily detect a precondition violation, but it can't know
what to do in order to fix the problem, that's the job of some higher
level. So for this kind of problem, an exception (or return code if
exceptions aren't used) is the correct option.
A function can't detect a postcondition violation; if the postcondition
is violated (when the precondition was met,) then the programmer did
something wrong. An exception shouldn't be thrown in this case, the
programmer should fix the code instead.
I know "precondition violation" and "postcondition violation" are not as
sexy as "bug" and "error," but that's how I roll I guess. :-)