Capture calls to the getDbusProperty method

We should catch the exception to prevent a coredump when calling the
getDbusProperty method.

Change-Id: I83a8b48f8007989279dd34cfc4f29ca96bb7965e
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
diff --git a/sensordatahandler.hpp b/sensordatahandler.hpp
index db80a69..3d56971 100644
--- a/sensordatahandler.hpp
+++ b/sensordatahandler.hpp
@@ -176,16 +176,25 @@
     GetSensorResponse response{};
 
     enableScanning(&response);
+    try
+    {
+        auto service = ipmi::getService(bus, sensorInfo.sensorInterface,
+                                        sensorInfo.sensorPath);
+        auto propValue = ipmi::getDbusProperty(
+            bus, service, sensorInfo.sensorPath,
+            sensorInfo.propertyInterfaces.begin()->first,
+            sensorInfo.propertyInterfaces.begin()->second.begin()->first);
 
-    auto service = ipmi::getService(bus, sensorInfo.sensorInterface,
-                                    sensorInfo.sensorPath);
-
-    auto propValue = ipmi::getDbusProperty(
-        bus, service, sensorInfo.sensorPath,
-        sensorInfo.propertyInterfaces.begin()->first,
-        sensorInfo.propertyInterfaces.begin()->second.begin()->first);
-
-    setAssertionBytes(static_cast<uint16_t>(std::get<T>(propValue)), &response);
+        setAssertionBytes(static_cast<uint16_t>(std::get<T>(propValue)),
+                          &response);
+    }
+    catch (const std::exception& e)
+    {
+        lg2::error(
+            "Failed to call readingAssertion, path: {PATH}, interface: {INTERFACE}: {ERROR}",
+            "PATH", sensorInfo.sensorPath, "INTERFACE",
+            sensorInfo.sensorInterface, "ERROR", e);
+    }
 
     return response;
 }
@@ -236,13 +245,26 @@
     }
 #endif
 
-    auto propValue = ipmi::getDbusProperty(
-        bus, service, sensorInfo.sensorPath,
-        sensorInfo.propertyInterfaces.begin()->first,
-        sensorInfo.propertyInterfaces.begin()->second.begin()->first);
+    double value{};
+    try
+    {
+        auto propValue = ipmi::getDbusProperty(
+            bus, service, sensorInfo.sensorPath,
+            sensorInfo.propertyInterfaces.begin()->first,
+            sensorInfo.propertyInterfaces.begin()->second.begin()->first);
 
-    double value = std::get<T>(propValue) *
-                   std::pow(10, sensorInfo.scale - sensorInfo.exponentR);
+        value = std::get<T>(propValue) *
+                std::pow(10, sensorInfo.scale - sensorInfo.exponentR);
+    }
+    catch (const std::exception& e)
+    {
+        lg2::error(
+            "Failed to call readingData, path: {PATH}, interface: {INTERFACE}: {ERROR}",
+            "PATH", sensorInfo.sensorPath, "INTERFACE",
+            sensorInfo.sensorInterface, "ERROR", e);
+        return response;
+    }
+
     int32_t rawData =
         (value - sensorInfo.scaledOffset) / sensorInfo.coefficientM;