From d107ce5161df82a6959b3e1dff350ac34a7b0bb2 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 22 Feb 2024 15:28:42 +0100 Subject: [PATCH] Match error behaviour of old boost::fibers-based code --- src/cosim.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cosim.cpp b/src/cosim.cpp index 5ddf165..ecbaa2b 100644 --- a/src/cosim.cpp +++ b/src/cosim.cpp @@ -153,6 +153,7 @@ struct cosim_execution_s cosim::entity_index_maps entity_maps; std::thread t; std::future simulate_result; + std::exception_ptr simulate_exception_ptr; std::atomic state; int error_code; }; @@ -576,9 +577,16 @@ void execution_async_health_check(cosim_execution* execution) if (execution->simulate_result.valid()) { const auto status = execution->simulate_result.wait_for(std::chrono::duration()); if (status == std::future_status::ready) { - execution->simulate_result.get(); + try { + execution->simulate_result.get(); + } catch (...) { + execution->simulate_exception_ptr = std::current_exception(); + } } } + if (auto ep = execution->simulate_exception_ptr) { + std::rethrow_exception(ep); + } } int cosim_execution_stop(cosim_execution* execution) @@ -586,6 +594,9 @@ int cosim_execution_stop(cosim_execution* execution) try { execution->cpp_execution->stop_simulation(); if (execution->t.joinable()) { + if (execution->simulate_exception_ptr) { + std::rethrow_exception(execution->simulate_exception_ptr); + } if (execution->simulate_result.valid()) { execution->simulate_result.get(); }