Error code for getPrintableValue API

This commit updates getPrintableValue API to set error code in case of
error. This helps the caller of API to take action based on the error
code returned from the API.

Change-Id: I15ff039f781af2dfd7d507fcaaa875716232f00e
Signed-off-by: Rekha Aparna <vrekhaaparna@ibm.com>
diff --git a/vpd-manager/include/utility/common_utility.hpp b/vpd-manager/include/utility/common_utility.hpp
index 6c28f5b..dfb194f 100644
--- a/vpd-manager/include/utility/common_utility.hpp
+++ b/vpd-manager/include/utility/common_utility.hpp
@@ -185,30 +185,38 @@
  * value, returns the hex represented value of the given data in string format.
  *
  * @param[in] i_keywordValue - Data in binary format.
- *
- * @throw - Throws std::bad_alloc or std::terminate in case of error.
+ * @param[out] o_errCode - To set error code in case of error.
  *
  * @return - Returns the converted string value.
  */
-inline std::string getPrintableValue(const types::BinaryVector& i_keywordValue)
+inline std::string getPrintableValue(const types::BinaryVector& i_keywordValue,
+                                     uint16_t& o_errCode)
 {
-    bool l_allPrintable =
-        std::all_of(i_keywordValue.begin(), i_keywordValue.end(),
-                    [](const auto& l_byte) { return std::isprint(l_byte); });
-
+    o_errCode = 0;
     std::ostringstream l_oss;
-    if (l_allPrintable)
+    try
     {
-        l_oss << std::string(i_keywordValue.begin(), i_keywordValue.end());
-    }
-    else
-    {
-        l_oss << "0x";
-        for (const auto& l_byte : i_keywordValue)
+        bool l_allPrintable = std::all_of(
+            i_keywordValue.begin(), i_keywordValue.end(),
+            [](const auto& l_byte) { return std::isprint(l_byte); });
+
+        if (l_allPrintable)
         {
-            l_oss << std::setfill('0') << std::setw(2) << std::hex
-                  << static_cast<int>(l_byte);
+            l_oss << std::string(i_keywordValue.begin(), i_keywordValue.end());
         }
+        else
+        {
+            l_oss << "0x";
+            for (const auto& l_byte : i_keywordValue)
+            {
+                l_oss << std::setfill('0') << std::setw(2) << std::hex
+                      << static_cast<int>(l_byte);
+            }
+        }
+    }
+    catch (const std::exception& l_ex)
+    {
+        o_errCode = error_code::STANDARD_EXCEPTION;
     }
 
     return l_oss.str();
diff --git a/vpd-manager/src/listener.cpp b/vpd-manager/src/listener.cpp
index 9fd4017..eee4771 100644
--- a/vpd-manager/src/listener.cpp
+++ b/vpd-manager/src/listener.cpp
@@ -521,8 +521,16 @@
                     std::get_if<types::BinaryVector>(&i_propertyValue))
             {
                 // convert property value to string before updating
+                uint16_t l_errCode = 0;
+                l_valueToUpdate =
+                    commonUtility::getPrintableValue(*l_val, l_errCode);
 
-                l_valueToUpdate = commonUtility::getPrintableValue(*l_val);
+                if (l_errCode)
+                {
+                    throw std::runtime_error(
+                        "Failed to get binary value in string, error : " +
+                        commonUtility::getErrCodeMsg(l_errCode));
+                }
             }
             else if (const auto l_val =
                          std::get_if<std::string>(&i_propertyValue))