From 3a6b0df34fc18cd7d8aa9b4793d35485ef110f2d Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Mon, 4 Mar 2024 09:54:11 +0100 Subject: [PATCH] Fix uncaught C++ exception in runAmiciSimulation (#2338) Previously, an exception during `ReturnData::processSimulationObjects` would result in program termination. Fixes #1882. --- src/amici.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/amici.cpp b/src/amici.cpp index 6e85dde857..ecff1ea786 100644 --- a/src/amici.cpp +++ b/src/amici.cpp @@ -220,10 +220,20 @@ std::unique_ptr runAmiciSimulation( ); } - rdata->processSimulationObjects( - preeq.get(), fwd.get(), bwd_success ? bwd.get() : nullptr, posteq.get(), - model, solver, edata - ); + try { + rdata->processSimulationObjects( + preeq.get(), fwd.get(), bwd_success ? bwd.get() : nullptr, posteq.get(), + model, solver, edata + ); + } catch (std::exception const& ex) { + rdata->status = AMICI_ERROR; + if (rethrow) + throw; + logger.log( + LogSeverity::error, "OTHER", "AMICI simulation failed: %s", + ex.what() + ); + } rdata->cpu_time_total = cpu_timer.elapsed_milliseconds();