From d143dd7076f876919bc73c047b9a14794b3c7763 Mon Sep 17 00:00:00 2001 From: v4hn Date: Thu, 2 Sep 2021 22:47:03 +0200 Subject: [PATCH] simplify exception handling This could have been done already back when `runCompute` was introduced. Wrapping the calls in try/catch comes from the previous implementation directly calling `compute()`. --- .../include/moveit/task_constructor/stage_p.h | 6 +++- core/src/container.cpp | 35 ++++--------------- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/core/include/moveit/task_constructor/stage_p.h b/core/include/moveit/task_constructor/stage_p.h index 7e51458c..87ed7b27 100644 --- a/core/include/moveit/task_constructor/stage_p.h +++ b/core/include/moveit/task_constructor/stage_p.h @@ -152,7 +152,11 @@ public: void runCompute() { ROS_DEBUG_STREAM_NAMED("Stage", "Computing stage '" << name() << "'"); auto compute_start_time = std::chrono::steady_clock::now(); - compute(); + try { + compute(); + } catch (const Property::error& e) { + me()->reportPropertyError(e); + } auto compute_stop_time = std::chrono::steady_clock::now(); total_compute_time_ += compute_stop_time - compute_start_time; } diff --git a/core/src/container.cpp b/core/src/container.cpp index 470017bd..52016014 100644 --- a/core/src/container.cpp +++ b/core/src/container.cpp @@ -643,14 +643,9 @@ bool SerialContainer::canCompute() const { void SerialContainer::compute() { for (const auto& stage : pimpl()->children()) { - try { - if (!stage->pimpl()->canCompute()) - continue; - - stage->pimpl()->runCompute(); - } catch (const Property::error& e) { - stage->reportPropertyError(e); - } + if (!stage->pimpl()->canCompute()) + continue; + stage->pimpl()->runCompute(); } } @@ -781,11 +776,7 @@ bool WrapperBase::canCompute() const { } void WrapperBase::compute() { - try { - wrapped()->pimpl()->runCompute(); - } catch (const Property::error& e) { - wrapped()->reportPropertyError(e); - } + wrapped()->pimpl()->runCompute(); } bool Alternatives::canCompute() const { @@ -797,11 +788,7 @@ bool Alternatives::canCompute() const { void Alternatives::compute() { for (const auto& stage : pimpl()->children()) { - try { - stage->pimpl()->runCompute(); - } catch (const Property::error& e) { - stage->reportPropertyError(e); - } + stage->pimpl()->runCompute(); } } @@ -840,11 +827,7 @@ void Fallbacks::compute() { if (!active_child_) return; - try { - active_child_->pimpl()->runCompute(); - } catch (const Property::error& e) { - active_child_->reportPropertyError(e); - } + active_child_->pimpl()->runCompute(); } void Fallbacks::onNewSolution(const SolutionBase& s) { @@ -894,11 +877,7 @@ bool Merger::canCompute() const { void Merger::compute() { for (const auto& stage : pimpl()->children()) { - try { - stage->pimpl()->runCompute(); - } catch (const Property::error& e) { - stage->reportPropertyError(e); - } + stage->pimpl()->runCompute(); } }