97 Things Every Programmer Should Know

(Chris Devlin) #1

(^56) 97 Things Every Programmer Should Know


Don’t Nail Your Program into the Upright Position ...........


Verity Stob


i ONCE WROTE A SPOOF C++ qUiz, in which I satirically suggested the fol-
lowing strategy for exception handling:


By dint of plentiful try...catch constructs throughout our codebase, we are
sometimes able to prevent our applications from aborting. We think of the resul-
tant state as “nailing the corpse in the upright position.”

Despite my levity, I was actually summarizing a lesson I received at the knee of
Dame Bitter Experience herself.


It was a base application class in our own, homemade C++ library. It had suf-
fered the pokings of many programmers’ fingers over the years: nobody’s hands
were clean. It contained code to deal with all escaped exceptions from every-
thing else. Taking our lead from Yossarian in Catch-22, we decided, or rather felt
(decided implies more thought than went into the construction of this monster)
that an instance of this class should live forever or die in the attempt.


To this end, we intertwined multiple exception handlers. We mixed in
Windows’ structured exception handling with the native kind (remember
try...except in C++? Me, neither). When things threw unexpectedly, we
tried calling them again, pressing the parameters harder. Looking back, I like to
think that when writing an inner try...catch handler within the catch clause
of another, some sort of awareness crept over me that I might have accidentally
taken a slip road from the motorway of good practice into the aromatic but
insalubrious lane of lunacy. However, this is probably retrospective wisdom.

Free download pdf