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()`.
This commit is contained in:
v4hn 2021-09-02 22:47:03 +02:00 committed by Michael Görner
parent 1e10aaccfd
commit d143dd7076
2 changed files with 12 additions and 29 deletions

View File

@ -152,7 +152,11 @@ public:
void runCompute() { void runCompute() {
ROS_DEBUG_STREAM_NAMED("Stage", "Computing stage '" << name() << "'"); ROS_DEBUG_STREAM_NAMED("Stage", "Computing stage '" << name() << "'");
auto compute_start_time = std::chrono::steady_clock::now(); auto compute_start_time = std::chrono::steady_clock::now();
try {
compute(); compute();
} catch (const Property::error& e) {
me()->reportPropertyError(e);
}
auto compute_stop_time = std::chrono::steady_clock::now(); auto compute_stop_time = std::chrono::steady_clock::now();
total_compute_time_ += compute_stop_time - compute_start_time; total_compute_time_ += compute_stop_time - compute_start_time;
} }

View File

@ -643,14 +643,9 @@ bool SerialContainer::canCompute() const {
void SerialContainer::compute() { void SerialContainer::compute() {
for (const auto& stage : pimpl()->children()) { for (const auto& stage : pimpl()->children()) {
try {
if (!stage->pimpl()->canCompute()) if (!stage->pimpl()->canCompute())
continue; continue;
stage->pimpl()->runCompute(); stage->pimpl()->runCompute();
} catch (const Property::error& e) {
stage->reportPropertyError(e);
}
} }
} }
@ -781,11 +776,7 @@ bool WrapperBase::canCompute() const {
} }
void WrapperBase::compute() { void WrapperBase::compute() {
try {
wrapped()->pimpl()->runCompute(); wrapped()->pimpl()->runCompute();
} catch (const Property::error& e) {
wrapped()->reportPropertyError(e);
}
} }
bool Alternatives::canCompute() const { bool Alternatives::canCompute() const {
@ -797,11 +788,7 @@ bool Alternatives::canCompute() const {
void Alternatives::compute() { void Alternatives::compute() {
for (const auto& stage : pimpl()->children()) { for (const auto& stage : pimpl()->children()) {
try {
stage->pimpl()->runCompute(); stage->pimpl()->runCompute();
} catch (const Property::error& e) {
stage->reportPropertyError(e);
}
} }
} }
@ -840,11 +827,7 @@ void Fallbacks::compute() {
if (!active_child_) if (!active_child_)
return; return;
try {
active_child_->pimpl()->runCompute(); active_child_->pimpl()->runCompute();
} catch (const Property::error& e) {
active_child_->reportPropertyError(e);
}
} }
void Fallbacks::onNewSolution(const SolutionBase& s) { void Fallbacks::onNewSolution(const SolutionBase& s) {
@ -894,11 +877,7 @@ bool Merger::canCompute() const {
void Merger::compute() { void Merger::compute() {
for (const auto& stage : pimpl()->children()) { for (const auto& stage : pimpl()->children()) {
try {
stage->pimpl()->runCompute(); stage->pimpl()->runCompute();
} catch (const Property::error& e) {
stage->reportPropertyError(e);
}
} }
} }