Home > Articles > Programming > C/C++

  • Print
  • + Share This
From the author of

More Information

You can find a much more exhaustive discussion of exception safety and techniques for writing exception-safe code in Appendix E, "Standard-Library Exception Safety," in The C++ Programming Language, Special Edition (Addison-Wesley, 2000, ISBN 0-201-70073-5), here abbreviated TC++PL for simplicity. If you have a version of TC++PL without that appendix, you can download a copy of the appendix from my home pages at http://www.research.att.com/~bs.

If you're not acquainted with exceptions in C++, I strongly recommend that you learn about them and their proper use. Used well, exceptions can significantly simplify code. Naturally, I recommend TC++PL, but any modern C++ book—:meaning one that's written to take advantage of the ISO C++ standard and its standard library—:should have an explanation.

If you're not yet comfortable with standard library facilities such as string and vector, I strongly encourage you to try them. Code that directly messes around with memory management and elements in arrays is among the most prone to resource leaks and nasty exception-safety problems. Such code is rarely systematic and the data structures involved rarely have simple and useful invariants. A very brief introduction to basic standard library facilities can be found in Chapter 3 of TC++PL, "A Tour of the Standard Library.'' That, too, can be downloaded from my home pages.

Copyright (c) 2001 Bjarne Stroustrup

  • + Share This
  • 🔖 Save To Your Account