开发者

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_ptr object that refers to a copy of e, ...

Use of either make_exception_ptr or current_exception is fine, depending on what exception you're trying to set.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜