CppCon 2021 has ended
Back To Schedule
Thursday, October 28 • 2:00pm - 3:00pm
Using Coroutines to Implement C++ Exceptions for Freestanding Environments

Log in to save this to your schedule, view media, leave feedback and see who's attending!

Feedback form is now closed.
The current design of C++ exceptions lead to many reasons and excuses to disable them. They require outstanding unwinding libraries, ABI specific support, slow failure paths, metadata that increases binary size, RTTI (run time type information), and many more. Putting costs and overhead aside, it is often impractical, or holds significant implementation barriers, to implement the necessary support for C++ exceptions in every environment - kernel, custom OS, hypervisors, embedded, or an arbitrary freestanding environment with limited or no C++ runtime libraries.

Writing code using exceptions is great though! The programmer gets to focus on the actual story of what the program is doing, and not worry too much about error propagation that happens automatically whenever an exception is thrown.

So how do we avoid the manual error propagation that is usually followed by turning off exceptions? We use Macros(!), of course, to propagate the errors via return value, such as CHECK_ERROR(expression), RIGHT? Well... Not in this talk.

In this session we are going to use the only tool I know of, that is both available in standard C++20, and gives us the ability to automatically propagate errors. If you read the title, you already know that this tool was not meant to be used for that purpose - that is C++20 Coroutines!

We are going to not only run without exceptions, we are turning off RTTI as well, as we get inspired by this alternative method of throwing exceptions, observe some cool optimizations such as memory allocation elisions, analyze the assembly code of coroutines, and more. We will even get the link to the open source library that I wrote for this talk, so that you could try it yourself!

This talk is for you if you want to get inspired on a unique usage of coroutines, not commonly seen before, or if you are working on kernel / freestanding code and like the use of exceptions. I hope that after this talk the audience plays with the thought that maybe in the future, exceptions could be implemented as a standard library feature, using a core language machinery such as coroutines, or some evolution or adaptation of it to this great use case.

How to prepare for the talk - please be familiar with C++20 coroutines, just the basic understanding is enough.

ALL TALK SESSIONS CAN BE ACCESSED FROM THE MAIN LOBBY: https://cppcon.digital-medium.co.uk/

avatar for Eyal Zedaka

Eyal Zedaka

Device Security Engineering Manager, Magic Leap
Eyal Zedaka is a technical leader. He is a C++ knowledge center, lecturer in various C++ courses, and an author of C++ open source software in the areas of low level OS, and pure C++ frameworks. Eyal is now working at Magic Leap, an Augmented Reality (AR) device company, as manager... Read More →

Thursday October 28, 2021 2:00pm - 3:00pm MDT