From cppreference.com
classfuture_error;(since C++11)The class
defines an exception object that is thrown on failure by the functions in the thread library that deal with asynchronous execution and shared states (
,
, etc). Similar to
, this exception carries an error code compatible with
.
Inheritance diagram
Member functions
creates a std::future_error object
(public member function)
replaces the std::future_error object
(public member function)
returns the error code
(public member function)
returns the explanatory string specific to the error code
(public member function)
Inherited from
Inherited from
Member functions
[virtual]
destroys the exception object
(virtual public member function of std::exception)
[virtual]
returns an explanatory string
(virtual public member function of std::exception)
Example
Run this code
#include<future>#include<iostream>intmain(){std::future<int>empty;try{intn=empty.get();// The behavior is undefined, but// some implementations throw std::future_error}catch(conststd::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" See also