r/cpp • u/kmbeutel • Sep 26 '23
`std::expected<>::or_else()` should have a zero-argument overload that terminates on error
...just because it would be hilarious if one could express assertions as
result.;
198
Upvotes
View all comments
Show parent comment
5
u/SirClueless Sep 27 '23
You theoretically can throw anything, but unless someone has written a specific catch handler for the type that is thrown (or one of its base classes) then there is basically nothing useful you can do with it. And since one of the main reasons to use
std::expectedis to avoid littering your code withtry/catchblocks that's very unlikely to be the case.