Using Coroutines to Implement C++ Exceptions for Freestanding Environments
summary
Claim: implement C++ exceptions for freestanding environments using C++20 coroutines as the core mechanism, removing RTTI and avoiding unwind libraries. The implementation builds a throwing<T> type, elides coroutine heap allocation onto the stack, and shrinks assembly from ~400 to ~59 lines in examples; it propagates errors via co_await/co_return, works across translation units without LTO, and exposes an open source library on GitHub that actually runs and passes the shown tests. zero overhead and no RTTI.
AI-written summary · about
chapters (14)
- 0:00Intro
- 0:48Exceptions are for exceptional
- 9:03Library
- 16:33Behind the Scenes
- 17:53Analyzing the Assembly
- 26:01Simplifying the Main Function
- 30:56Proof
- 32:56Making Compiler Happy
- 36:12Translation Unit
- 38:12Exit Condition
- 40:46Result
- 47:05Summary
- 48:45Stacktrace
- 51:49QA
related talks
58mAn Introduction to C++ Coroutines
04mLightning Talk: Implementing Coroutines Using C++17
01h 02mC++20’s Coroutines for Beginners
55mC++20 coroutines as an API principle
01h 05mCoroutines: C++ vs Rust
06mImplementing coroutines using C++17
06mThrowing Exceptions for Fun and Profit
01h 05mWhy use coroutines for asynchronous applications
