std::future_error

定义于头文件 <future>
class future_error;
(C++11 起)

std::future_error 定义异常对象,它为处理异步执行和共享状态( std::futurestd::promise 等)的线程库中的函数在失败时抛出。同 std::system_error ,此异常携带与 std::error_code 兼容的错误码。

cpp/error/exceptioncpp/error/logic errorstd-future error-inheritance.svg
关于这幅图像

继承图

目录

成员函数

创建 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 << "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 错误码
(枚举)

版本历史

  • (当前 | 先前 2017年8月26日 (六) 20:12Fruderica讨论 | 贡献. . (1,399字节) (-519). . (撤销)
  • 当前 | 先前 2013年7月2日 (二) 11:31P12bot讨论 | 贡献 . . (1,918字节) (-114). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 19:54P12bot讨论 | 贡献 . . (2,032字节) (+249). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 03:08P12讨论 | 贡献 . . (1,783字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (1,783字节) (+1,783). . (Translated from the English version using Google Translate)