是否有方法指导swagger codegen为任务生成基于任务的延续,以捕获cpprest引发的异常? 我有一个带有CPPRET的Skigg代码生成的C++代码,它可以调用一些服务器。p>

是否有方法指导swagger codegen为任务生成基于任务的延续,以捕获cpprest引发的异常? 我有一个带有CPPRET的Skigg代码生成的C++代码,它可以调用一些服务器。p>,c++,swagger-codegen,cpprest-sdk,C++,Swagger Codegen,Cpprest Sdk,我面临的问题是: 如果cpprest http请求返回任何错误代码(4xx或5xx),则在CentOS Linux中运行程序时会出现以下崩溃。如果cpprest http请求返回成功,则我的程序不会崩溃 崩溃的调用堆栈: 0x00007fe97b987207 libc.so.6!gsignal(+0x37) 0x00007fe97b9888f8 libc.so.6!中止(+0x147) 0x0000000007f2478b MyServer!中止消息() 0x0000000007f24ae1 M

我面临的问题是: 如果cpprest http请求返回任何错误代码(4xx或5xx),则在CentOS Linux中运行程序时会出现以下崩溃。如果cpprest http请求返回成功,则我的程序不会崩溃

崩溃的调用堆栈:

0x00007fe97b987207 libc.so.6!gsignal(+0x37) 0x00007fe97b9888f8 libc.so.6!中止(+0x147) 0x0000000007f2478b MyServer!中止消息() 0x0000000007f24ae1 MyServer!Demanling_terminate_handler()() 0x0000000007f24983我的服务器!std::u终止(无效(*)())() 0x0000000007f24a05 MyServer!std::terminate()(+0x44) 0x00007fe97a417734 libstdc++.so.6_ZSt17rethrow_exception nst15_exception_ptr13 exception_ptrE(+0x73) 0x00007fe97c9fdc05 libMyLibrary.so_ZN4PPLX7详细信息16_例外持有人21_RethrowUserExceptionEv(+0x24) 0x00007fe97c9fea05 libMyLibrary.so_ZN4pplx7details15_Task_impl_base5_WaitEv(+0x2e4) 0x00007fe97c9faab6 libMyLibrary.so_ZN5Test18MyManager16CallServerApi1EPKwS2\u ibS2\u Pwm(+0x615)

说明: 基本上,MyLibrary共享对象有一个函数CallServerApi1(),该函数再次调用swagger代码gen中名为CallServerApi1()的函数,该函数发出cpprest请求

以下代码位于swagger生成的代码中MyApi类的CallServerApi1()函数中:

 return m_ApiClient->callApi(path, utility::conversions::to_string_t("POST"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
    .then([=](web::http::http_response response)
    {
        // 1xx - informational : OK
        // 2xx - successful       : OK
        // 3xx - redirection   : OK
        // 4xx - client error  : not OK
        // 5xx - client error  : not OK
        if (response.status_code() >= 400)
        {
            //throw my exception with details in case http returned a error response code.
            throw MyException(response.status_code()
                , utility::conversions::to_string_t("error calling CallServerApi1: ") + response.reason_phrase()
                , std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
        }
        return response.extract_string(); // If successfull return the response data
     });

我在这里读到:这表明

当您在传递给任务对象的工作函数体中引发异常时,运行时将存储该异常并将其封送到调用concurrency::task::get或concurrency::task::wait的上下文中

当任务引发异常时,其基于任务的延续将计划运行

我的理解是,由于swagger生成的代码具有基于任务的延续性,并且崩溃调用堆栈有一行声明pplx正在抛出用户异常

图书馆,所以_ZN4PPLX7详细信息16_例外持有人21_RethrowUserExceptionEv(+0x24)

cpprest似乎正在重新抛出异常,由于基于值的延续,它没有被swagger生成的代码处理,因此它崩溃了,因为libstdc++标准被指示为重新抛出异常而这样做。有人能解释一下这一点吗?是否可能是这样?如果是这样,有没有办法通知swagger code gen使用基于任务的延续而不是基于值的延续,以允许cpprest的异常通过then()块并在该块内处理

        try
        {

            auto task = api.CallServerApi1();
            task.wait();
            if (task.is_done())
            {

            }
        }
        catch (const MyException& e)
        {
            string error = e.what();
            int error = e.error_code().value();
        }