首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::future_error

Defined in header <future>

?

?

class future_error;

?

(since C++11)

全班std::future_error定义一个异常对象,该异常对象在线程库中处理异步执行和共享状态%28的函数失败时抛出。std::future,,,std::promise,等...%29。类似于std::system_error,此异常带有与std::error_code...

二次

二次

继承图

成员函数

(constructor)

creates a std::future_error object (public member function)

code

returns the error code (public member function)

what

returns the explanatory string specific to the error code (public member function)

继承自STD:逻辑[医]误差

继承自STD:例外

成员函数

(destructor) virtual

destructs the exception object (virtual public member function of std::exception)

what virtual

returns an explanatory string (virtual public member function of std::exception)

二次

代码语言:javascript
复制
#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";
    }
}

二次

可能的产出:

二次

代码语言:javascript
复制
Caught a future_error with code "future:3"
Message: "No associated state"

二次

另见

future_errc (C++11)

identifies the future error codes (enum)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com