[3] In fact, you might want to always specify exception objects by const reference in exception handlers. It’s very rare to modify and rethrow an exception. We are not dogmatic about this practice however.
[4] Only
[5] For more detail on auto_ptr, see Herb Sutter’s article entitled, "Using auto_ptr Effectively" in the October 1999 issue of the
[6] If you’re interested in a more in-depth analysis of exception safety issues, the definitive reference is Herb Sutter’s
[7] The library function uncaught_exception( ) returns true in the middle of stack unwinding, so technically you can test uncaught_exception( ) for false and let an exception escape from a destructor. We’ve never seen a situation in which this constituted good design, however, so we only mention it in this footnote.
[8] Some compilers do throw exceptions in these cases, but they usually provide a compiler option to disable this (unusual) behavior.
[9] This depends, of course, on how much checking of return codes you would have to insert if you weren’t using exceptions.
[10] Borland enables exceptions by default; to disable exceptions use the -x- compiler option. Microsoft disables support by default; to turn it on, use the -GX option. With both compilers use the -c option to compile only.
[11] The GNU C++ compiler uses the zero-cost model by default. Metrowerks Code Warrior for C++ also has an option to use the zero-cost model.
[12] Thanks to Scott Meyers and Josee Lajoie for their insights on the zero-cost model. You can find more information on how exceptions work in Josee’s excellent article, "Exception Handling: Behind the Scenes,"
[13] Among other things he invented Quicksort.
[14] As quoted in
[15] See his book,
[16] This is still an assertion
[17] There is a nice phrase to help remember this phenomenon: "Require no more; promise no less," first coined in
[18] This section is based on Chuck’s article, "The Simplest Automated Unit Test Framework That Could Possibly Work", C/C++ Users Journal, Sept. 2000.
[19] A good book on this subject is Martin Fowler's
[20] Lightweight methodologies such as XP have "joined forces" in the Agile Alliance (see http://www.agilealliance.org/home).
[21] Our Date class is also "internationalized", in that it supports wide character sets. This is introduced at the end of the next chapter.
[22] See http://sourceforge.net/projects/cppunit for more information.
[23] "Runtime Type Identification", discussed in chapter 9. Specifically, we use the name( ) member function of the typeinfo class. By the way, if you're using Microsoft Visual C++, you need to specify the compile option /GR. If you don't, you'll get an access violation at runtime.
[24] In particular, we use
[25] Batch files and shell scripts work well for this, of course. The Suite class is a C++-based way of organizing related tests.
[26] Our key technical reviewer, Pete Becker of Dinkumware. Ltd., brought to our attention that it is illegal to use macros to replace C++ keywords. His take on this technique was as follows: ""This is a dirty trick. Dirty tricks are sometimes necessary to figure out why code isn't working, so you may want to keep this in your toolbox, but don't ship any code with it." Caveat programmer :-).