Some Pitfalls for Exceptions
C++98: Unchecked Exceptions
From More Effective C++, Item 14:
"If a function throws an exception not listed in its exception specification, that fault is detected at runtime, and the special function
unexpected
is automatically invoked....
The default behavior for
unexpected
is to callterminate
, and the default behavior forterminate
is to callabort
, so the default behavior for a program with a violated exception specification is to halt. Local variables in active stack frames are not destroyed, because abort shuts down program execution without performing such cleanup. A violated exception specification is therefore a cataclysmic thing, something that should almost never happen."
Java: Checked Exceptions
From StackOverflow: The case against checked exceptions.
"What I'm saying is that checked exceptions as implemented in Java behave, in practice, more like return values as in C than they do the traditional ‘exceptions’ we might recognise from C++ and other pre-Java languages. And that IMO this does indeed lead to confusion and poor design."