Exceptional C++
240 pages
English
PDF
4.5

Exceptional C++

Exceptional C++

Author:

Year:

Summary:

Introduction

The book "Exceptional C++" (1999) by Herb Sutter is not a textbook for beginners, but a collection of 50 engineering problems that will make you truly think about how you write C++ code. In a world where software reliability is valued more than writing speed, this book remains a benchmark for deep understanding of the language. Sutter doesn't just give answers — he teaches you to think in terms of exceptional situations, resource management, and designing error-resistant interfaces.

Despite the book being over 20 years old, its ideas (RAII, exception guarantees, smart pointers) have become the foundation of modern C++ (C++11 and later). If you want to stop fearing exceptions and start writing code that doesn't "crash" at the worst possible moment — this book is for you.

What the book is about

"Exceptional C++" is structured in a "question-answer" format (problem — solution — analysis). Each chapter covers a separate aspect of reliable programming:

  • Exceptions and safety: how to write functions that don't leak resources and leave objects in a consistent state even when errors occur.
  • RAII (Resource Acquisition Is Initialization): why this is the main C++ idiom and how to apply it for managing memory, files, mutexes.
  • Templates and generic programming: intricacies of instantiation, partial specialization, SFINAE.
  • Inheritance and polymorphism: how to properly design class hierarchies without violating the Liskov substitution principle.
  • Memory management: new/delete operators, placement new, operator overloading.
  • Interface design: how to make an API that is difficult to use incorrectly.

Who this book is for

The book is intended for C++ programmers who already have experience (at least 1-2 years of active development). It will be useful for:

  • Developers who want to write reliable production code.
  • Those preparing for technical interviews (problems from the book are often found at Google, Microsoft, Yandex).
  • Teachers and mentors looking for examples to analyze in seminars.
  • Everyone who wants to understand the "why" behind standard C++ idioms, not just the "how".

What the reader will learn

After reading, you will be able to:

  • Formulate and verify exception guarantees (basic, strong, nothrow) for your functions.
  • Properly use std::auto_ptr (and its modern counterparts unique_ptr/shared_ptr) for automatic resource management.
  • Avoid pitfalls when overloading operators (especially operator= and operator[]).
  • Design classes that work correctly in STL containers.
  • Understand when and how to use mutable, volatile, const_cast without harming the architecture.
  • Write template functions that don't blow up when substituting unsuitable types (SFINAE).
  • Implement the copy-and-swap idiom for safe assignment.

Strengths

  • Depth and practicality. Each problem is a real issue from the author's experience. You won't find abstract examples like "cat-dog".
  • "Question-answer" format. You can start reading from any chapter. Perfect for "coffee breaks" — 15 minutes per problem.
  • Focus on "why". Sutter explains not only the correct solution but also the motivation: why other options are bad, what trade-offs exist.
  • Writing style. Lively, with a touch of humor and self-irony. The book is not like a dry reference manual.
  • Timeless value. Even in the era of C++20/23, the principles of RAII and exception safety remain unchanged. The book teaches the fundamentals that do not become obsolete.

Who is it recommended for

Recommendations