“Exception Handling: A False Sense of Security”

This is the 25th-anniversary year of Tom Cargill’s article “Exception Handling: A False Sense of Security,” which appeared in C++ Report magazine (November/December 1994).

I suspect that most members of the C++ community vastly underestimate the skills needed to program with exceptions and therefore underestimate the true costs of their use. The popular belief is that exceptions provide a straightforward mechanism for adding reliable error handling to our programs. On the contrary, I see exceptions as a mechanism that may cause more ills than it cures. Without extraordinary care, the addition of exceptions to most software is likely to diminish overall reliability and impede the software development process.

This “extraordinary care” demanded by exceptions originates in the subtle interactions among language features that can arise in exception handling. Counter-intuitively, the hard part of coding exceptions is not the explicit throws and catches. The really hard part of using exceptions is to write all the intervening code in such a way that an arbitrary exception can propagate from its throw site to its handler, arriving safely and without damaging other parts of the program along the way.

In the October 1993 issue of the C++ Report, David Reed argues in favor of exceptions […] To illustrate my concerns concretely I will examine the code that appeared in Reed’s article.

Cargill’s article is well worth reading from beginning to end. (Read it at the link above; or here (PDF); or it’s reprinted on paper in Stan Lippman’s C++ Gems: Programming Pearls from The C++ Report (1997).) The state of C++ programming has improved dramatically in the past 25 years; but I dare say that most published code still would not survive a close reading, with respect to exception-safety. (See also: “Fetishizing class invariants” (February 2019).)

Unfortunately, the article Cargill was rebutting — David R. Reed’s “Exceptions: pragmatic issues with a new language feature” (October 1993) — doesn’t seem to be accessible these days; it’s not reprinted in Lippman’s book and it’s not online anywhere that I’m aware of. If you know where to find a copy, drop me a line!

Posted 2019-06-17