STD未来异常-已检索,STD错误
std future exception - already retrieved, std bug?
我正在尝试捕获已经检索的异常,如http://www.cplusplus.com/reference/future/future_errc/
所示。try {
prom.get_future();
prom.get_future(); // throws std::future_error with future_already_retrieved
}
catch (std::future_error& e) {
if (e.code() == std::make_error_condition(std::future_errc::future_already_retrieved))
std::cerr << "[future already retrieved]n";
else
std::cerr << "[unknown exception]n";
}
但是我总是收到一个无状态的期望。通过查看std的未来实现:
_Ty& _Get_value() const
{ // return the stored result or throw stored exception
if (!valid()) // will check if already retrieved, and return false
_Throw_future_error(make_error_code(future_errc::no_state));
return (_Assoc_state->_Get_value(_Get_only_once)); // only this
// method can throw the already retrieved exception but its not
// being hit because of previous valid() check
}
这是Visual Studio 2013中的一个bug还是一个功能?
从我发现更可靠的cppreference:
如果*this没有共享状态或get_future已经被调用,则抛出异常。
什么异常?
抛出:future_error如果
*this
没有共享状态,或者如果get_future已经在与*this具有相同共享状态的promise上被调用。
- (14.1) future_already_retrieve如果get_future已经被调用
- (14.2) no_state if *this is no shared state
所以这是MSVC2013中的一个bug
相关文章:
- 使用std::source_location报告错误的最佳实践
- std::is_base_of表示ctor编译错误
- 多个文件的内存分配错误"在抛出 'std :: bad_alloc' what (): std :: bad_alloc 的实例后终止调用" [C++]
- 程序崩溃并显示"std::out_of_range"错误
- 在c++中尝试对对象数组进行排序时,出现std:bad_alloc错误
- 我收到以下错误:抛出'std::bad_alloc'实例后终止调用
- 尝试使用 std::vector<std::thread时出现静态断言失败错误>
- 错误 C2679:二进制"<<":未找到采用类型 'std::string_view' 的右侧操作数的运算符(或者没有可接受的转换)
- 为什么 std::绑定错误参数可以成功?
- std::cout输出int时出现编译错误
- 使用静态库与 std::jthread (g++-10) 的分段错误
- std::unordered_map 类型对象声明期间出现"field has incomplete type"错误
- 在缺少函数重载时抛出异常,并带有 std::variant 而不是编译时错误
- 使用 memcpy() 复制到 std::chrono::milliseconds 会给出错误 -Werror=clas
- 显式 std::exception_ptr 转换为 bool 不存在.VS2010 错误?
- "random_shuffle":不是"std"错误的成员
- VC++ 2010 "array is not a member of std"错误
- 开发C++ "to_string is not a member of std"错误
- STD未来异常-已检索,STD错误
- 交叉编译c++的树莓派std错误