From 16662c1bfc7fe2c78014d978572c2795db91280f Mon Sep 17 00:00:00 2001 From: hellkite500 Date: Wed, 27 Mar 2024 15:39:32 -0600 Subject: [PATCH] feat: catch formulation errors and report feature and timestep (closes #777) --- include/core/Layer.hpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/core/Layer.hpp b/include/core/Layer.hpp index 5aed53ac28..583ba2566f 100644 --- a/include/core/Layer.hpp +++ b/include/core/Layer.hpp @@ -3,6 +3,7 @@ #include "LayerData.hpp" #include "Simulation_Time.hpp" +#include "State_Exception.hpp" #ifdef NGEN_MPI_ACTIVE #include "HY_Features_MPI.hpp" @@ -92,7 +93,17 @@ namespace ngen auto r = features.catchment_at(id); //TODO redesign to avoid this cast auto r_c = std::dynamic_pointer_cast(r); - double response = r_c->get_response(output_time_index, simulation_time.get_output_interval_seconds()); + double response(0.0); + try{ + response = r_c->get_response(output_time_index, simulation_time.get_output_interval_seconds()); + } + catch(models::external::State_Exception& e){ + std::string msg = e.what(); + msg = msg+" at timestep "+std::to_string(output_time_index) + +" ("+current_timestamp+")" + +" at feature id "+id; + throw models::external::State_Exception(msg); + } std::string output = std::to_string(output_time_index)+","+current_timestamp+","+ r_c->get_output_line_for_timestep(output_time_index)+"\n"; r_c->write_output(output);