Re: Exception Misconceptions: Exceptions are for unrecoverable errors.
"dragan" <spambuster@prodigy.net> writes:
Saying "Exceptions are for unrecoverable errors" seems to
imply that they are to be used only or mostly in such
situations.
BTW: Who did actually say this?
Whereas the exception machinery in C++ was developed
primarily to handle and RECOVER from more errors more
elegantly than was possible without exceptions, the statement
is highly suspect.
More elegantly? Actually, for correct and secure C++ code,
all functions need to be written to be ?exception safe?, but
only a minority of C++ programmers does so or even is aware
of it.
Those "unrecoverable errors" are probably the things that
assertion checking weeds out during development time rather
than being an application for exception machinery.
These are distinct concepts for me: An unrecoverable error
can occur when a program needs 10 Bytes of allocated
storage, but this storage is not available. The program can
not generate more storage, so the error is not recoverable,
but it also can not be weeded out during developement time.
Futher discussion of the application of exceptions is
appreciated.
I prefer error results to exceptions. So all I would write
about exceptions would start with ?If I was forced to use a
language that would force me to use exceptions ...?
The applications of error results is as follows:
if( attempt( to_do_something ))
{ case 0: /* ok, continue */ ... break;
case 1: /* oops, handle */ ... break;
... }