3 ms·
As lasagnaphil said, with optional and result types exceptions can be restricted to signaling coding errors instead of any errors. Think vector::at (good) vers
by blub 9y ago
As lasagnaphil said, with optional and result types exceptions can be restricted to signaling coding errors instead of any errors.
Think vector::at (good) versus std::stoi (bad).
- AstralStorm 9y agoWhat will you do if you do not check if the optional actually has a value? (What happens: you get an exception at the moment of dereference and potentially lose the information about the cause.)
- steveklabnik 9y agoThis is true of some languages with these constructs (C++, Scala, AFAIK) but not all (Rust, Haskell). Given that this is a C++ thread, you’re right, but that’s an issue of the particular language, not the idea generally.
- blub 9y agoActually it's UB by default, so first of all, one should either always use optional::value() or wrap the class. Secondly... yes, that's why exceptions also need good logging/tracing for best results.