The expected outcome

Speaker: Ivan Čukić

Audience level:

There is a plethora of ways to do error handling in C++ and all have their pros and cons.

In C++23, we got yet another option to encode errors in the types themselves with std::expected. Some features are still missing and will only come in C++26, but as this is a library feature, we can easily roll up a complete "expected" and use it long before 2026 comes knocking. There are also alternatives to std::expected in the form of Boost.Outcome which, albeit with some philosophical and practical differences, model a similar thing.

In this talk, we will cover what std::expected and similar types are all about and how they can be used for unified error handling. We will also see some more advanced usage patterns that make working with expected-like types a more pleasant task than doing the if-error-handle-else-proceed dance all the time.

The last part of the talk will focus on integrating expected-like types with C++20 coroutines for people who want to have a more familiar syntax for handling errors with expected-like types that looks like try-catch blocks that we have with C++'s exceptions, but without all the baggage that exceptions bring with them.

While the ideas that will be covered in the talk are very beginner friendly, some implementation details that we'll cover are more involved.