Exception propagation and std::future

前端 未结 2 1174
滥情空心
滥情空心 2021-02-19 09:39

My understanding is that when an asynchronous operation throws an exception, it will be propagated back to a thread that calls std::future::get(). However, when su

2条回答
  •  不思量自难忘°
    2021-02-19 10:11

    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 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;
    }
    

提交回复
热议问题