2011-09-25 19 views
9

我發現在幾個地方如何承諾應引用copy_exception,但我無法在當前的FDIS中找到它。自從這些博客以後,如何使用set_exception()還有其他方法嗎?如何獲取promise :: set_exception(x)的參數?

例如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 
    } 
} 

我發現std::current_exception()here

catch(...) 
{ 
    p.set_exception(std::current_exception()); 
} 

所以我的問題:

  • 我應該總是使用current_exception(),即使我不明白 「...」?
  • 或者是否有新的不同名稱copy_exception

回答

14

copy_exception有一個不同的名稱。 copy_exception被改名爲後期在標準化過程中超過它實際做的困惑:

template<class E> 
    exception_ptr make_exception_ptr(E e) noexcept; 

影響:創建一個exception_ptr對象是指 e副本,...

使用make_exception_ptrcurrent_exception是好的,這取決於您嘗試設置的例外情況。