How to get the argument for promise::set_exception(x)?
I found in several places on how a promise should be used references to copy_exception, but I can not find it in the current FDIS. Is there an alternative way on how to use set_exception() since those blogs?
For example here
void asyncFun(promise<int> intPromise)
{
int result;
try {
// calculate the result
intPromise.set_value(result);
} catch (MyException e) {
intPromise.set_exception(std::copy_exception(e)); // <- copy
}
}
I find std::current_exception() here.
catch(...)
{
p.set_exception(std::curr开发者_JS百科ent_exception());
}
Therefore my questions:
- Should I always use
current_exception(), even when I do not catch "..."? - Or is there new a different name for
copy_exception?
There is a different name for copy_exception. copy_exception was renamed late in the standardization process over confusion of what it actually did:
template<class E>
exception_ptr make_exception_ptr(E e) noexcept;
Effects: Creates an
exception_ptrobject that refers to a copy ofe, ...
Use of either make_exception_ptr or current_exception is fine, depending on what exception you're trying to set.
加载中,请稍侯......
精彩评论