|
|
Defined in header <future> | ||
class future_error; | (since C++11) | |
The classstd::future_error defines an exception object that is thrown on failure by the functions in the thread library that deal with asynchronous execution and shared states (std::future,std::promise, etc). Similar tostd::system_error, this exception carries an error code compatible withstd::error_code.
Inheritance diagram
Contents |
creates astd::future_error object(public member function)[edit] | |
replaces thestd::future_error object(public member function)[edit] | |
returns the error code (public member function)[edit] | |
returns the explanatory string specific to the error code (public member function)[edit] |
[virtual] | destroys the exception object (virtual public member function of std::exception )[edit] |
[virtual] | returns an explanatory string (virtual public member function of std::exception )[edit] |
#include <future>#include <iostream> int main(){std::future<int> empty;try{int n= empty.get();// The behavior is undefined, but// some implementations throw std::future_error}catch(const std::future_error& e){std::cout<<"Caught a future_error with code\""<< e.code()<<"\"\nMessage:\""<< e.what()<<"\"\n";}}
Possible output:
Caught a future_error with code "future:3"Message: "No associated state"
(C++11) | identifies the future error codes (enum)[edit] |