More Exceptional C++
More Exceptional C++
Summary:
Introduction
The book "More Exceptional C++" (2001) is a continuation of the famous collection of problems and solutions by Herb Sutter, one of the leading experts in the C++ language. If the first book "Exceptional C++" laid the foundation for a deep understanding of exceptions, memory management, and class design, then the second part raises the bar even higher. Here, the author offers 40 new problems (Items), divided into thematic sections that cover both classic issues (exception safety, RAII, idioms) and more advanced topics: STL optimization, intricacies of inheritance, templates, and even multithreading issues (in the context of C++98/03). The book is written in a "question-answer" format: first a problem is posed, then a detailed analysis is given with code, analysis, and conclusions. This is not a textbook for beginners — it is a collection of puzzles for those who already write confidently in C++ and want to avoid common pitfalls.
What the book is about
The main theme is exception safety and correct resource management. Sutter systematically explains how to write code that does not "leak" when exceptions occur, how to use the RAII (Resource Acquisition Is Initialization) idiom, and how to design classes that are resilient to partial execution of operations. The book also covers:
- Rules for operator overloading (especially operator= and operator[]);
- Intricacies of working with STL containers (std::vector, std::list, std::map);
- The "pimpl" (pointer to implementation) and "copy-and-swap" idioms;
- Problems of multiple inheritance and virtual base classes;
- Code optimization using templates and policy-based design;
- Error handling in constructors and destructors.
Each chapter contains specific code examples that can be immediately applied in real projects. Sutter not only provides ready-made solutions but also explains why other approaches are erroneous and what consequences may arise.
Who this book is for
The book is intended for experienced C++ developers who are already familiar with syntax, classes, inheritance, and templates. It will be useful for:
- Programmers working on high-reliability systems (finance, telecom, embedded systems);
- Library and framework developers where API stability is important;
- Senior students and postgraduates studying advanced C++ concepts;
- Anyone who wants to improve their skills in debugging and refactoring complex code.
Beginners will find the book difficult — it is better to start with "Exceptional C++" or "Effective C++" by Scott Meyers.
What the reader will learn
After reading, you will be able to:
- Guarantee exception safety at three levels (basic, strong, nothrow);
- Correctly implement assignment and copy operators;
- Avoid memory and resource leaks in constructors;
- Optimize the use of STL containers (e.g., avoid unnecessary copying);
- Apply the "copy-and-swap" idiom to write a reliable operator=;
- Understand when to use virtual inheritance and when to use composition;
- Design classes with possible exceptions in destructors in mind.
Strengths
The main advantage of the book is its practical focus. Each problem is accompanied by real code that can be compiled and tested. Sutter is not afraid to show incorrect options and explain why they are dangerous. The second plus is the structure: the book is divided into short chapters (2–5 pages), allowing you to read it in snippets and return to complex topics. Third, the emphasis on exception safety remains relevant even after 20 years: modern C++ (C++11/14/17/20) has added new tools (move semantics, unique_ptr, optional), but the basic principles laid out by Sutter have not become outdated. Finally, the author's style — lively, with a dose of humor and self-irony — makes