From 47d22cae41e86f7ce648067399678845b5fd5c00 Mon Sep 17 00:00:00 2001 From: Denis Nutiu Date: Sat, 1 Aug 2020 16:28:35 +0300 Subject: [PATCH] Handle ArgumentException in Bme680Sensor --- NucuCar.Sensors/Environment/Bme680Sensor.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/NucuCar.Sensors/Environment/Bme680Sensor.cs b/NucuCar.Sensors/Environment/Bme680Sensor.cs index a8b85f3..b54f2b4 100644 --- a/NucuCar.Sensors/Environment/Bme680Sensor.cs +++ b/NucuCar.Sensors/Environment/Bme680Sensor.cs @@ -101,9 +101,11 @@ namespace NucuCar.Sensors.Environment } catch (System.IO.IOException e) { - Logger?.LogError($"{DateTimeOffset.Now}:BME680 Sensor initialization FAIL."); - Logger?.LogTrace(e.Message); - CurrentState = SensorStateEnum.Error; + HandleInitializationException(e); + } + catch (ArgumentException e) + { + HandleInitializationException(e); } } @@ -169,5 +171,12 @@ namespace NucuCar.Sensors.Environment } public Bme680Sensor Object { get; } + + private void HandleInitializationException(Exception e) + { + Logger?.LogError($"{DateTimeOffset.Now}:BME680 Sensor initialization FAIL."); + Logger?.LogDebug(e.Message); + CurrentState = SensorStateEnum.Error; + } } } \ No newline at end of file