Fix failure in reading power value during PowerOff state

D-Bus sensor object to read power value is not created during
PowerOff state. Fixed to return 0 power value if sensor object
is not present.

Change-Id: Ibe340cab0483c7a711081197b932aaba0408d333
Signed-off-by: Marri Devender Rao <devenrao@in.ibm.com>
diff --git a/dcmihandler.cpp b/dcmihandler.cpp
index 11befdc..bfc8466 100644
--- a/dcmihandler.cpp
+++ b/dcmihandler.cpp
@@ -1037,18 +1037,28 @@
         elog<InternalFailure>();
     }
 
-    auto service = ipmi::getService(bus, SENSOR_VALUE_INTF, objectPath);
+    // Return default value if failed to read from D-Bus object
+    int64_t power = 0;
+    try
+    {
+        auto service = ipmi::getService(bus, SENSOR_VALUE_INTF, objectPath);
 
-    //Read the sensor value and scale properties
-    auto properties = ipmi::getAllDbusProperties(
-                            bus, service, objectPath, SENSOR_VALUE_INTF);
-    auto power = properties[SENSOR_VALUE_PROP].get<int64_t>();
-    auto scale = properties[SENSOR_SCALE_PROP].get<int64_t>();
+        //Read the sensor value and scale properties
+        auto properties = ipmi::getAllDbusProperties(
+                                bus, service, objectPath, SENSOR_VALUE_INTF);
+        auto value = properties[SENSOR_VALUE_PROP].get<int64_t>();
+        auto scale = properties[SENSOR_SCALE_PROP].get<int64_t>();
 
-    // Power reading needs to be scaled with the Scale value using the formula
-    // Value * 10^Scale.
-    power *= std::pow(10, scale);
-
+        // Power reading needs to be scaled with the Scale value using the
+        // formula Value * 10^Scale.
+        power = value * std::pow(10, scale);
+    }
+    catch (std::exception& e)
+    {
+        log<level::INFO>("Failure to read power value from D-Bus object",
+                        entry("OBJECT_PATH=%s", objectPath),
+                        entry("INTERFACE=%s", SENSOR_VALUE_INTF));
+    }
     return power;
 }