writefrudata: catch exceptions in sdbusplus call

Catch sdbusplus call exceptions.

Change-Id: Iff0b2a4265061c90ebac78f90e4183f5e36037ef
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/writefrudata.cpp b/writefrudata.cpp
index 371fa6c..2bbf48e 100644
--- a/writefrudata.cpp
+++ b/writefrudata.cpp
@@ -16,11 +16,13 @@
 #include <fstream>
 #include <iostream>
 #include <memory>
+#include <phosphor-logging/log.hpp>
 #include <sdbusplus/server.hpp>
 #include <sstream>
 #include <vector>
 
 using namespace ipmi::vpd;
+using namespace phosphor::logging;
 
 extern const FruMap frus;
 extern const std::map<Path, InterfaceMap> extras;
@@ -265,15 +267,19 @@
 
     mapperCall.append(path);
     mapperCall.append(std::vector<std::string>({intf}));
-
-    auto mapperResponseMsg = bus.call(mapperCall);
-    if (mapperResponseMsg.is_method_error())
-    {
-        throw std::runtime_error("ERROR in mapper call");
-    }
-
     std::map<std::string, std::vector<std::string>> mapperResponse;
-    mapperResponseMsg.read(mapperResponse);
+
+    try
+    {
+        auto mapperResponseMsg = bus.call(mapperCall);
+        mapperResponseMsg.read(mapperResponse);
+    }
+    catch (const sdbusplus::exception::SdBusError& ex)
+    {
+        log<level::ERR>("Exception from sdbus call",
+                        entry("WHAT=%s", ex.what()));
+        throw;
+    }
 
     if (mapperResponse.begin() == mapperResponse.end())
     {
@@ -325,7 +331,7 @@
     {
         service = getService(bus, intf, path);
     }
-    catch (const std::runtime_error& e)
+    catch (const std::exception& e)
     {
         std::cerr << e.what() << "\n";
         return -1;
@@ -403,12 +409,17 @@
     auto pimMsg = bus.new_method_call(service.c_str(), path.c_str(),
                                       intf.c_str(), "Notify");
     pimMsg.append(std::move(objects));
-    auto inventoryMgrResponseMsg = bus.call(pimMsg);
-    if (inventoryMgrResponseMsg.is_method_error())
+
+    try
     {
-        std::cerr << "Error in notify call\n";
+        auto inventoryMgrResponseMsg = bus.call(pimMsg);
+    }
+    catch (const sdbusplus::exception::SdBusError& ex)
+    {
+        log<level::ERR>("Error in notify call", entry("WHAT=%s", ex.what()));
         return -1;
     }
+
     return rc;
 }