dbus: dbuswrite: add try/catch block on calls

The dbus calls can now except, therefore add try/catch blocks and report
the errors.

Change-Id: I8cae2576922fa9316065ef048e674beb48a58e88
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/dbus/dbuswrite.cpp b/dbus/dbuswrite.cpp
index b691b66..fab9b4a 100644
--- a/dbus/dbuswrite.cpp
+++ b/dbus/dbuswrite.cpp
@@ -18,11 +18,14 @@
 
 #include <iostream>
 #include <memory>
+#include <phosphor-logging/log.hpp>
 #include <sdbusplus/bus.hpp>
 #include <string>
 
 constexpr const char* pwmInterface = "xyz.openbmc_project.Control.FanPwm";
 
+using namespace phosphor::logging;
+
 // this bus object is treated as a singleton because the class is constructed in
 // a different thread than it is used, and as bus objects are relatively
 // expensive we'd prefer to only have one
@@ -75,11 +78,18 @@
                                   "org.freedesktop.DBus.Properties", "Set");
     mesg.append(pwmInterface, "Target",
                 sdbusplus::message::variant<uint64_t>(ovalue));
-    auto resp = writeBus->call(mesg);
-    if (resp.is_method_error())
+
+    try
     {
-        std::cerr << "Error sending message to " << path << "\n";
+        // TODO: if we don't use the reply, call_noreply()
+        auto resp = writeBus->call(mesg);
     }
+    catch (const sdbusplus::exception::SdBusError& ex)
+    {
+        log<level::ERR>("Dbus Call Failure", entry("PATH=%s", path.c_str()),
+                        entry("WHAT=%s", ex.what()));
+    }
+
     oldValue = static_cast<int64_t>(ovalue);
     return;
 }
@@ -115,11 +125,18 @@
                                   "org.freedesktop.DBus.Properties", "Set");
     mesg.append(pwmInterface, "Target",
                 sdbusplus::message::variant<uint64_t>(value));
-    auto resp = writeBus->call(mesg);
-    if (resp.is_method_error())
+
+    try
     {
-        std::cerr << "Error sending message to " << path << "\n";
+        // TODO: consider call_noreplly
+        auto resp = writeBus->call(mesg);
     }
+    catch (const sdbusplus::exception::SdBusError& ex)
+    {
+        log<level::ERR>("Dbus Call Failure", entry("PATH=%s", path.c_str()),
+                        entry("WHAT=%s", ex.what()));
+    }
+
     oldValue = static_cast<int64_t>(value);
     return;
 }