std::future_error
来自 cppreference.cn
在头文件 <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(); // 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"; } }
可能的输出
Caught a future_error with code "future:3" Message: "No associated state"
[编辑] 参阅
(C++11) |
标识 future 错误代码 (枚举) |