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

Adrian Fagg adrianf at evaluategroup.com
Fri Dec 3 05:02:13 EST 2004


> -----Original Message-----
> From: effective-cpp-bounces at accu.org
> [mailto:effective-cpp-bounces at accu.org]On Behalf Of Hammond, Peter

> The article suggests, nay states, that all code needs to be
> exception safe.
> This only true where the application needs to carry on after
> an exception.
> This depends on what exceptions are used for of course, but
> in my experience
> they are used to report very bad things in libraries, and the
> application
> tells the user and gives up. In that case it doesn't much
> matter if it leaks
> memory or other resources, or classes become unstable,
> because they are not
> called any more.
>
> 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.

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.

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.

The bottom line is simply:

Why not just do it right?

Regards,

Adrian

Work: mailto:adrianf at evaluategroup.com
Home: mailto:adrian.fagg at ntlworld.com

Pretty pictures: http://homepage.ntlworld.com/rbyadf/




More information about the Effective-cpp mailing list