【发布时间】:2019-05-17 05:17:19
【问题描述】:
我有一个程序,它使用计时器在 GUI 应用程序中设置一些双缓冲区。在一些罕见的情况下,例如,当程序关闭时,我收到一个错误,即设置此缓冲区的承诺已设置。有没有办法捕捉到这个错误并处理它?
这是一个最小的例子:
#include <iostream>
#include <boost/thread/future.hpp>
int main()
{
boost::promise<int> promise;
try {
promise.set_value(0);
promise.set_value(0);
} catch (...) {
promise.set_exception(boost::current_exception());
}
return 0;
}
无论我如何尝试捕捉它,它都会以错误终止我的程序:
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::promise_already_satisfied> >'
here 你可以看到它的实际效果。
【问题讨论】:
标签: c++ c++11 promise future boost-thread