On Mar 5, 2:35 pm, "Daniel T." <danie...@earthlink.net> wrote:
"Nevin :-] Liber" <ne...@eviloverlord.com> wrote:
"Daniel T." <danie...@earthlink.net> wrote:
In my experience (and it might be just in my domain,) if an
exception is thrown, then it is because a programmer made an
unwarranted assumption while writing some particular piece of
code and the code should be fixed so the exception is no longer
thrown.
(In my problem domain, you are describing ASSERT, not exceptions.)
Several people have made comments like this one. I can imagine a
domain where just asserting and aborting the program, or allowing a
bug that wasn't found during test time to put the program in an
undefined state, would be a very bad thing; such systems would use
exceptions to do some sort of reset and problem logging. However,
that isn't my domain.
I style my code after the standard when it comes to exceptions. A
thrown exception means that the code that detected the programmer
error, is not the code that needs to be fixed. (Precondition
violations.)
Trying to allocate a resource and it failing is a programmer error?
Interesting point of view, but it doesn't work.
Exceptions are not for programming errors, there are for errors that
shouldn't happen ideally but may well happen anyway, and still need to
be correctly dealt with (at least, if you want to write code of decent
quality).
For programming errors, you use asserts, which abort the program if a
precondition has been violated, because the program is in a state it
definitely should never be in, and there is no way to recover from
that.
[ comp.lang.c++.moderated. First time posters: Do this! ]