Stewart Stremler wrote:
C++ has exceptions. Only two problems with C++ exceptions:
(1) They're not accepted as universal, so "best practices" results in a
set of macros to "portably handle exceptions". You don't use try, you
use a MACROPREFIX_TRY, and a MACROPREFIX_END_TRY, and all that stuff...
plus you have to keep track of nested try-catch blocks, and use custom
throw macros, and so forth. It makes the whole exception thing so
useless that you might as well not use it at all, which is, I suspect,
the point.
Yeah, this is a boorish habit. Fortunately it is no longer considered
"best practices". If you think callers might need an exception free
interface, the best practices approach is now to provide a std::nothrow
version of your function. For a really cool notion of how to merge the
best of C++ exceptions and C-style return codes (not to mention a
demonstration of the flexibility and power of C++), check out Andrei
Alexandrescu's "The Power of None":
/http://www.*nwcpp.org*/Downloads/2006/*The_Power_of_None*.ppt/
(2) You can't get meaningful information from an unknown exception.
Sure, you can "catch ( ... )", which will catch an unknown exception,
but you have absolutely no way of learning anything at all about that
exception. No stack traces for you!
I can't say I've ever worked with a C++ runtime that didn't provide
stack traces for exceptions. That said, the lack of a standard interface
to stack traces is a PITA. I believe the standards committee is working
on this. As awful as things are when it happens, hitting a "catch (...)"
is generally a sign that you are in some serious trouble/or writing a
library you expect to be used by third parties. Generally having "catch
(std::exception)" is sufficient.
But... C++ advocates get to say that C++ has exceptions. The fact that
they aren't really _useful_ doesn't mean they don't gleefully check the
little language-feature checkbox.
C++ exceptions generally weren't useful for an extended period of time,
but by the time the language was standardized most of the key problems
were addressed. The C++ exception specification does have its problems,
as does Java's, but you can (again, assuming some degree of proficiency)
safely avoid/work around the problem parts and get quite useful results.
--Chris
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg