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() {
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;
}

View File

@ -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();
}
}