C++ Error Handling
summary
Examines a simple C++ generator class (configure + operator()) and then actually adds and compares real error strategies: logging to cerr (cheap but fragile), throwing std::runtime_error and small custom exception types (keeps happy path unchanged but forces unwind/RAII and changes control flow), returning bool or enum/status (easy but frequently ignored), returning string or status object, out-parameter/last_error, std::optional vs std::expected (optional loses diagnostics; expected handles void too), and mapping exceptions into return values; concludes error handling multiplies code and choices, so examples omit it.
AI-written summary · about
chapters (17)
- 0:00Error handling in C++
- 1:33Why error handling is omitted
- 5:47Context-dependent error handling
- 10:43Error reporting five Ws
- 17:29Who needs error messages
- 21:07Support teams and error design
- 25:58Error message information
- 33:37Where to send logs
- 38:13Simple C++ example
- 42:08Adding comments and logging
- 49:13Reporting errors with exceptions
- 53:24Exceptions and control flow
- 1:01:12Returning error statuses
- 1:14:25Handling errors in non-void
- 1:22:15Using expected for errors
- 1:26:58Exceptions vs return codes
- 1:28:23Conclusion
related talks
44mError handling in C++: as easy as "use exceptions"?
45mTo Err is Human - Robust Error Handling in C++26
01h 03m“What Could Possibly Go Wrong?: A Tale of Expectations and Exceptions”
01h 02mBack to Basics: Exception Handling and Exception Safety
53mThe Dawn Of A New Error
54mTypical C++, But Why?
59mExpect the expected
01h 04mKEYNOTE: De-fragmenting C++: Making exceptions more affordable and usable
