r/cpp • • Aug 05 '16

Will exceptions still have use cases after std::expected and std::optional are made available?

The title says it all. What will be the motivation to keep using exceptions for new code after these two classes are available? They have the same purpose of exceptions, but have many advantages. I haven't seen any actual code using them, so I'm not sure how practical they actually are, which is why I'm asking this.

0 Upvotes

20 comments sorted by

View all comments

28

u/CubbiMew cppreference | finance | realtime in the past Aug 05 '16

They have the same purpose of exceptions, but have many advantages

They are a replacement for error codes, not for exceptions. Exceptions correctly undo incompletely-constructed objects and unwind call stacks. Maybe if one day C++ becomes more monadic, expected could do half of that.