[Exceptional C++ Style] Item 12: Exception Safety: Is it Wort hit?

Hammond, Peter peter.hammond at amsjv.com
Mon Dec 6 04:57:14 EST 2004


> > -----Original Message-----
> > From: effective-cpp-bounces at accu.org
> > [mailto:effective-cpp-bounces at accu.org]On Behalf Of Hammond, Peter
> 
> > Now I know this is a very simplistic view of the world, but
> > it works. I read
> > thse articles and they make perfect sense, but then I try to
> > apply them to
> > the day job and find that we are not going to continue anyway
> > so it would be
> > a waste of effort.
> >
> > So how do you justify either using exceptions or not using them?
> 
> As I see it, it's a fundamental code quality issue. C++ code 
> that doesn't
> meet the basic guarantee is inherently fragile and no easier 
> to write than
> code that does.

Agreed that it is inherently fragile. Disagreed that it is no easier to
write. If nothing else, it relies on people being aware of the issues, and
that alone takes effort. If everyone was, for example, taught to use smart
pointers from day one, and "new" was some obscure part of the langauge
internals, it might work, but that's not the way anyone I know was taught.

> 
> OK, if you've got some legacy applications that aren't up to 
> scratch, leave
> them be. I wouldn't try to build anything new on such a code 
> base though.

In an ideal world yes. In the real world, much as I would like to, nobody is
going to let me scrap certain of our product code bases because "everyone
knows exception safe code is good". And of course, because we are working on
legacy code with the no-guarantee guarantee, we cant throw and catch
exceptions, so why bother making the new code exception safe? And so on.

> 
> The fact that you can 'get away' with what is essentially 
> unexpected program
> termination, shouldn't be the guiding factor here. Sooner or 
> later you'll
> find occasions when you don't get away with it.

Yep, agreed completely. In the ideal world.
> 
> The bottom line is simply:
> 
> Why not just do it right?

Because (a) it costs money and (b) the engineers have to understand the
issues and then want to put them right. :(

Pete.

********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************



More information about the Effective-cpp mailing list