Browse Source

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.
pull/24/head
Maurice Makaay 3 years ago
parent
commit
015866f5ab
2 changed files with 8 additions and 3 deletions
  1. +4
    -2
      light/color_instant_handler.h
  2. +4
    -1
      light/color_white_light.h

+ 4
- 2
light/color_instant_handler.h View File

@ -41,8 +41,10 @@ class ColorInstantHandler : public GPIOOutputs {
white_light_->copy_to(this); white_light_->copy_to(this);
else if (rgb_light_->set_light_color_values(v)) else if (rgb_light_->set_light_color_values(v))
rgb_light_->copy_to(this); 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; return true;
} }


+ 4
- 1
light/color_white_light.h View File

@ -119,7 +119,10 @@ class ColorWhiteLight : public GPIOOutputs {
for (RGBWLevelsByTemperature& item : table) for (RGBWLevelsByTemperature& item : table)
if (temperature >= item.from_temperature) if (temperature >= item.from_temperature)
return item; 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];
} }
}; };


Loading…
Cancel
Save