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