public member function
<future>

std::future_error::what

const char* what() const noexcept;
獲取與異常關聯的訊息
返回描述異常的訊息。

此訊息包含code().message()返回的字串。

引數



返回值

描述異常的 C 字串。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// future_error::what example:
#include <iostream>     // std::cout
#include <future>       // std::promise, std::future_error

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.what() << '\n';
  }

  return 0;
}

可能的輸出(訊息是實現特定的)

future_error caught: promise already satisfied


另見