|
|
|
|
|
by fluoridation
9 days ago
|
|
>std::vector::at(), std::optional::value() Both functions must return T &. If the vector is not long enough, or the object is not set, then returning a T & is impossible. So we have a function that has already been called and which must return something valid, and cannot return something valid. The only two ways to resolve this contradiction is to throw, or to terminate. (Well, you could also trigger undefined behavior like operator[]() and operator*(). No comment.) >And then there's std::system_error. And what am I supposed to conclude from the existence of a type? |
|
Or they’re bad APIs that should be redesigned to be not bad.
They’re fallible functions. Don’t write fallible APIs that require exceptions to report errors! That’s bad API design!