Exception propagation and std::future

℡╲_俬逩灬. 提交于 2019-12-05 01:03:33

It is ignored and discarded, just like if you wait() for a value but never get() it.

wait() simply says "block until the future is ready", be that ready with a value or exception. It's up to the caller to actually get() the value (or exception). Usually you'll just use get(), which waits anyway.

vs2012\vc11\crt\future.cpp

there is an error with the

static const char *const _Future_messages[] =
{   // messages for future errors
"broken promise",
"future already retrieved",
"promise already satisfied",
"no state"
};

this code generated an invalid acceso to "_Future_messages" because _Mycode.value() return 4.

    const char *__CLR_OR_THIS_CALL what() const _THROW0()
    {   // get message string
    return (_Get_future_error_what(_Mycode.value()));
    }

// code example

    std::future<int> empty;
try {
    int n = empty.get();
} catch (const std::future_error& e) {
   const error_code eCode = e.code();
   char *sValue = (char*)e.what();
   std::cout << "Caught a future_error with code " << eCode.message()
              << " - what" << sValue << endl;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!