我有一个程序,它使用计时器在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
你可以看到它在起作用。