From 015866f5ab7821ecae29a0e5d38d75b0e204de9f Mon Sep 17 00:00:00 2001 From: Maurice Makaay Date: Wed, 28 Apr 2021 13:09:22 +0200 Subject: [PATCH] Dropped the use of exceptions. I tried the codebase against the new esp-idf 4 alpha code, and the build didn't have exception handling enabled by default. I saw no problems with modifying the code to not raise exceptions, so I did so to be future-proof. The exception cases were cases that should not happen anyway, because the input that could trigger the exception has already been validated on beforehand by the Python-based code generation. --- light/color_instant_handler.h | 6 ++++-- light/color_white_light.h | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/light/color_instant_handler.h b/light/color_instant_handler.h index dc2eca9..b2e90d1 100644 --- a/light/color_instant_handler.h +++ b/light/color_instant_handler.h @@ -41,8 +41,10 @@ class ColorInstantHandler : public GPIOOutputs { white_light_->copy_to(this); else if (rgb_light_->set_light_color_values(v)) rgb_light_->copy_to(this); - else - throw std::logic_error("None of the GPIOOutputs classes handles the requested light state"); + else { + ESP_LOGE(TAG, "Light color error: (None of the GPIOOutputs classes handles the requested light state; defaulting to 'off'"); + off_light_->copy_to(this); + } return true; } diff --git a/light/color_white_light.h b/light/color_white_light.h index 6360b9d..ffdbb61 100644 --- a/light/color_white_light.h +++ b/light/color_white_light.h @@ -119,7 +119,10 @@ class ColorWhiteLight : public GPIOOutputs { for (RGBWLevelsByTemperature& item : table) if (temperature >= item.from_temperature) return item; - throw std::invalid_argument("received too low temperature"); + // Temperature too low. Shouldn't happen, because of validation + // at higher levels. But when it happens, simply return the data + // for lowest available temperature. + return table[0]; } };