Re: Are throwing default constructors bad style, and if so, why?
on Thu Oct 16 2008, JoshuaMaurice-AT-gmail.com wrote:
I agree completely. Exception use is so pervasive in normal C++ that
it's quite difficult to isolate and squash exceptions.
However, my company is trying: No exceptions anywhere. The performance
critical sections are a like a flashback of bad C I would expect to
see 15 years ago.
I was going to attempt to persuade them that exceptions are good, but
the argument is a little harder now in light of the my somewhat-
trivial tests showing significant exception handling overhead when no
exception is thrown.
Funnily enough, I'm pretty sure we don't actually catch all exceptions
from new and the standard library, meaning we get the worst of both
worlds: bad code from exception overhead paranoia and slow code from
the exception overhead we didn't deal with.
I'm of the opinion that if it really is a problem, a profiler will
pick it up, and we could take time to squash exceptions in that
performance critical area.
a. Why don't you do some more realistic testing?
b. If you want to avoid that overhead in code that you _know_ won't
throw, you can get a lot of mileage on MSVC by adding throw()
specifications. MSVC (non-conformingly) ignores its semantics and
uses it as an optimization hint.
c. All that aside, your last two paragraphs above seem to make a pretty
persuasive argument for the use of exceptions in the general case.
--
Dave Abrahams
BoostPro Computing
http://www.boostpro.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]