enum class
<future>
std::future_errc
Error conditions for future objects
This enum class
type defines the error conditions of the future category.
future_errc label | int value | description |
broken_promise | 0 | The promise object with which the future shares its shared state was destroyed before being set a value or an exception. |
future_already_retrieved | 1 | A future object was already retrieved from this provider. |
promise_already_satisfied | 2 | The promise object was already set a value or exception. |
no_state | 3 | An operation attempted to access the shared state of an object with no shared state. |
All library implementations define at least the values above, but may provide additional values.
future_errc label | int value | description |
broken_promise | * | The promise object with which the future shares its shared state was destroyed before being set a value or an exception. |
future_already_retrieved | * | A future object was already retrieved from this provider. |
promise_already_satisfied | * | The promise object was already set a value or exception. |
no_state | * | An operation attempted to access the shared state of an object with no shared state. |
* = A value different from zero (including
broken_promise). The particular values may vary according to library implementation, but these four values are guaranteed to exist and be distinct. Implementations may provide additional labels and values.
Values of the enum type future_errc may be used to create error_condition objects to be compared against the value returned by the code member of future_error.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
// std::future_errc example:
#include <iostream> // std::cerr
#include <future> // std::promise, std::future_error, std::future_errc
int main ()
{
std::promise<int> prom;
try {
prom.get_future();
prom.get_future(); // throws std::future_error with future_already_retrieved
}
catch (std::future_error& e) {
if (e.code() == std::make_error_condition(std::future_errc::future_already_retrieved))
std::cerr << "[future already retrieved]\n";
else std::cerr << "[unknown exception]\n";
}
return 0;
}
|
Output (on stderr):
[future already retrieved]
|
See also
- errc
- Generic error conditions (enum class)
- future_category
- Return future category (function)