3 ms·
What 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 los
by AstralStorm 9y ago
What 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.