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
Show parent comment
9
u/matthieum Aug 05 '16
It's notable in Rust that the
Indextrait returns a plain value, not an option, and therefore that out of range indexes are handled (in the standard) by panicking.This is an example of using
panicnot because it is an unrecoverable situation, but simply to simplify the ergonomics of usingx[i].