public member function
<future>

std::future_error::code

const error_code& code() const noexcept;
Get error code
Returns the error_code object associated with the exception.

Parameters

none

Return value

The error_code associated with the object.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// future_error::code example:
#include <iostream>     // std::cout
#include <future>       // std::promise, std::future_error
#include <string>       // operator<<(ostream&,const string&)

int main ()
{
  std::promise<int> prom;

  try {
    prom.get_future();
    prom.get_future();   // throws std::future_error
  }
  catch (std::future_error& e) {
    std::cout << "future_error caught: " << e.code().message() << '\n';
  }

  return 0;
}

Possible output (the message is implementation-specific):

future_error caught: promise already satisfied


See also