std::future_error
来自cppreference.com
<tbody>
</tbody>

| 在标头 <future> 定义
|
||
class future_error; |
(C++11 起) | |
类 std::future_error 定义异常对象,它由处理异步执行和共享状态(std::future、std::promise 等)的线程库中的函数在失败时抛出。同 std::system_error,此异常携带与 std::error_code 兼容的错误码。
继承图
成员函数
创建 std::future_error 对象 (公开成员函数) | |
替换 std::future_error 对象 (公开成员函数) | |
| 返回错误码 (公开成员函数) | |
| 返回特定于错误码的解释性字符串 (公开成员函数) |
继承自 std::logic_error
继承自 std::exception
成员函数
[虚] |
销毁该异常对象 ( std::exception 的虚公开成员函数)
|
[虚] |
返回解释性字符串 ( std::exception 的虚公开成员函数)
|
示例
运行此代码
#include <future>
#include <iostream>
int main()
{
std::future<int> empty;
try
{
int n = empty.get(); // 行为未定义,但一些实现抛出 std::future_error
}
catch (const std::future_error& e)
{
std::cout << "捕获了 future_error,其代码为 \"" << e.code()
<< "\"\n消息: \"" << e.what() << "\"\n";
}
}
可能的输出:
捕获了 future_error,其代码为 "future:3"
消息: "No associated state"
参阅
(C++11) |
鉴别未来体错误码 (枚举) |