SdBusError: Fix initialization checks

sd_bus_error_set_errno() is semantically useful in C for returning the
errno and constructing the error in a single call. However, since
successful population of the error can not be distinguished due to the
collapsed return value, we need another way to ensure the error was
built correctly. Don't check for the return of sd_bus_error_set_errno()
and instead use sd_bus_error_is_set().

Tested:
    Builds still work and tests still pass.

Change-Id: Ib7546d7bb19eb2ebbaf6e2cab79a8ecd8960f280
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/sdbusplus/exception.cpp b/sdbusplus/exception.cpp
index e8f1104..2bb3576 100644
--- a/sdbusplus/exception.cpp
+++ b/sdbusplus/exception.cpp
@@ -1,5 +1,8 @@
 #include <sdbusplus/exception.hpp>
 #include <sdbusplus/sdbus.hpp>
+#include <stdexcept>
+#include <system_error>
+#include <utility>
 
 extern sdbusplus::SdBusImpl sdbus_impl;
 
@@ -12,10 +15,14 @@
     std::system_error(error, std::generic_category()), error(SD_BUS_ERROR_NULL),
     intf(intf)
 {
-    if (error == ENOMEM ||
-        intf->sd_bus_error_set_errno(&this->error, error) == -ENOMEM)
+    // We can't check the output of intf->sd_bus_error_set_errno() because
+    // it returns the input errorcode. We don't want to try and guess
+    // possible error statuses. Instead, check to see if the error was
+    // constructed to determine success.
+    intf->sd_bus_error_set_errno(&this->error, error);
+    if (!intf->sd_bus_error_is_set(&this->error))
     {
-        throw std::bad_alloc();
+        throw std::runtime_error("Failed to create SdBusError");
     }
 
     populateMessage(prefix);