Exception handling for json_utility APIs
This commit adds code to handle exceptions for some of the json_utility
APIs. Each API will have output returned in case of error based on the
return type of the API instead of throwing an exception.
Also updated the caller of the json_utility APIs to handle the return
value.
Change-Id: Ib43028974b61c18a0edae96608a8764cb440234a
Signed-off-by: RekhaAparna01 <vrekhaaparna@ibm.com>
diff --git a/vpd-manager/src/backup_restore.cpp b/vpd-manager/src/backup_restore.cpp
index 294efc4..9de43b9 100644
--- a/vpd-manager/src/backup_restore.cpp
+++ b/vpd-manager/src/backup_restore.cpp
@@ -20,17 +20,14 @@
{
std::string l_backupAndRestoreCfgFilePath =
i_sysCfgJsonObj.value("backupRestoreConfigPath", "");
- try
+
+ m_backupAndRestoreCfgJsonObj =
+ jsonUtility::getParsedJson(l_backupAndRestoreCfgFilePath);
+
+ if (m_backupAndRestoreCfgJsonObj.empty())
{
- m_backupAndRestoreCfgJsonObj =
- jsonUtility::getParsedJson(l_backupAndRestoreCfgFilePath);
- }
- catch (const std::exception& ex)
- {
- logging::logMessage(
- "Failed to intialize backup and restore object for file = " +
- l_backupAndRestoreCfgFilePath);
- throw(ex);
+ throw JsonException("JSON parsing failed",
+ l_backupAndRestoreCfgFilePath);
}
}