Re: Exception Misconceptions: Exceptions are for unrecoverable errors.
In article <hgqoqj$srf$1@news.eternal-september.org>, "Alf P. Steinbach" <alfps@start.no> wrote:
* dragan:
Saying "Exceptions are for unrecoverable errors" seems to imply that they
are to be used only or mostly in such situations. 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.
Yes.
Those "unrecoverable errors" are probably the things that
assertion checking weeds out during development time rather than being an
application for exception machinery. "Unrecoverable error": throw up a
dialog for the developer and exit (or crash to keep the call stack in view
in the debugger). Exceptions, are more appropriately used where there is a
likelihood of recovering from the error condition rather than being just for
"unrecoverable errors".
C++ unfortunately lacks any concept exceptions that won't be caught by ordinary
catch(...). Therefore, in current C++ you should preferentially not use
exceptions for unrecoverable failures, not to speak of unrecoverable errors!
Just log and terminate.
In Java, there is a separation betwen exceptions and errors.
Exceptions could be used on a very fine grained level, such
as numeric string parsing, and in case there is a non digit
present, you simply catch the exception and replace the
result with default value. Works like a champ.
In fact, you MUST use try/catch block to do these conversion.
Otherwise, your code won't even compile.
With error, you are dead. You can not even recover from them.
Futher discussion of the application of exceptions
is appreciated. Keep in mind that while there are SOME general vague
"principles" of the application of exceptions, mostly the scenarios need to
be defined for fruitful discussion. Please keep the examples simple but
realistic and note the assumptions you make.
Hm, I failed to see the question in there, sorry.
Some people just feel they need to dominate, like THEIR word
is "the word of God". They tend to fail to comprehend that
THEIR view is just that, THEIR view. Nothing more than that.
Cheers & hth.,
- Alf
--
Programmer's Goldmine collections:
http://preciseinfo.org
Tens of thousands of code examples and expert discussions on
C++, MFC, VC, ATL, STL, templates, Java, Python, Javascript,
organized by major topics of language, tools, methods, techniques.