Throw custom exceptions on D-Bus method failures

All 3 fan applications - control, monitor, and presence
have cases where it is expected that a getProperty call
may fail because a sensor is missing.  While the applications
already handle this, the InternalFailure exception that was
being thrown by the underlying call generates log entries
that make it look like something bad happened.

The custom exceptions now being thrown do not log anything on
creation, but store all of the failing information so that
any callers could still log the info if they wanted to.

Tested: Boot a water cooled Witherspoon and see the fan presence
        and monitor applications not look like they are
        failing.  Boot a system without the fan hwmon running,
        and see fan-control-init still show the fails.

Change-Id: Ifd8ad6e3deb492bbaf33f12c7258125dce1e5ea8
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/control/main.cpp b/control/main.cpp
index cde71d0..dd9330d 100644
--- a/control/main.cpp
+++ b/control/main.cpp
@@ -18,6 +18,7 @@
 #include "argument.hpp"
 #include "manager.hpp"
 #include "event.hpp"
+#include "sdbusplus.hpp"
 
 using namespace phosphor::fan::control;
 using namespace phosphor::logging;
@@ -64,22 +65,41 @@
     //handle both sd_events (for the timers) and dbus signals.
     bus.attach_event(eventPtr.get(), SD_EVENT_PRIORITY_NORMAL);
 
-    Manager manager(bus, eventPtr, mode);
+    try
+    {
+        Manager manager(bus, eventPtr, mode);
 
-    //Init mode will just set fans to max and delay
-    if (mode == Mode::init)
-    {
-        manager.doInit();
-        return 0;
-    }
-    else
-    {
-        r = sd_event_loop(eventPtr.get());
-        if (r < 0)
+        //Init mode will just set fans to max and delay
+        if (mode == Mode::init)
         {
-            log<level::ERR>("Failed call to sd_event_loop",
-                            entry("ERROR=%s", strerror(-r)));
+            manager.doInit();
+            return 0;
         }
+        else
+        {
+            r = sd_event_loop(eventPtr.get());
+            if (r < 0)
+            {
+                log<level::ERR>("Failed call to sd_event_loop",
+                        entry("ERROR=%s", strerror(-r)));
+            }
+        }
+    }
+    //Log the useful metadata on these exceptions and let the app
+    //return -1 so it is restarted without a core dump.
+    catch (phosphor::fan::util::DBusServiceError& e)
+    {
+        log<level::ERR>("Uncaught DBus service lookup failure exception",
+                entry("PATH=%s", e.path.c_str()),
+                entry("INTERFACE=%s", e.interface.c_str()));
+    }
+    catch (phosphor::fan::util::DBusMethodError& e)
+    {
+        log<level::ERR>("Uncaught DBus method failure exception",
+                entry("BUSNAME=%s", e.busName.c_str()),
+                entry("PATH=%s", e.path.c_str()),
+                entry("INTERFACE=%s", e.interface.c_str()),
+                entry("METHOD=%s", e.method.c_str()));
     }
 
     return -1;