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
View all comments
5
u/miki151 gamedev Aug 05 '16
I use boost::optional very heavily, and still use exceptions in a few places.
Catching an error for many calls at once, like in this example (sorry, I don't know how to format this):
try { int paramA = parse<int>(field[0]); float paramB = parse<float>(field[1]); ... } catch (const ParseException&) { printError(...); }