Errors, debugging and testing

This part of the C++ course is about the program that fails. An exception unwinds the stack to the handler that knows what to do, and the guarantees of exception safety decide what a class promises while it does. A custom exception type names the error, noexcept carries a promise the compiler trusts, and std::expected returns an error without one. Assertions, GDB and the sanitizers find a crash in a debug build, and the part ends with a test runner written by hand and a test that does not depend on the wall clock.

7.1 Exceptions throw, try, catch, stack unwinding and a destructor that runs during unwinding Open 7.2 Exception safety the basic guarantee, the strong guarantee, copy and swap, and a leak that proves the point Open 7.3 Custom exception types derive from std::runtime_error, catch by reference, what() and a hierarchy of errors Open 7.4 noexcept a no-throw promise, std::terminate, move constructors and the vector reallocation that depends on it Open 7.5 std::expected return a value or an error, and_then, a parse that reports why it failed, and no exceptions Open 7.6 Assertions and static_assert assert in debug builds, NDEBUG, static_assert on a type and [[nodiscard]] Open 7.7 Debugging with GDB build with -g, break, run, next, print, backtrace and a crash that is read from the core Open 7.8 Sanitizers AddressSanitizer for a use after free, UndefinedBehaviorSanitizer for overflow and a clean run Open 7.9 Unit testing without a framework a CHECK macro, a test function per case, a runner that counts failures and a first regression Open 7.10 Testing files and time a temporary directory per test, injected clocks and a test that does not depend on the wall clock Open

Lessons