The way I understand things, assert
s should be used to check for programming errors and document conditions that should never happen, and exceptions should be used for runtime errors beyond the programmer's control (for example, getting a key_not_found
response from a database)
So then why is std::future_errc::no_state
a thing? An exception with that value can only be thrown when a future is accessed that does not have valid state. Which is something the programmer can control. Why not just encourage implementations to abort from a failed assertion when this happens?
For example if they return a future that has not been fetched from a call to std::promise::get_future()
then it will not have any valid state. Or calling get()
on a future twice.
Aucun commentaire:
Enregistrer un commentaire