Merge pull request 'added try catch for more safety' (#168) from mueller/catch-nlohmann-json into develop
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit
Reviewed-on: #168 Reviewed-by: Jakob.Meier <meierj@irs.uni-stuttgart.de>
This commit is contained in:
commit
f6a69e2eca
@ -11,7 +11,12 @@ ReturnValue_t NVMParameterBase::readJsonFile() {
|
||||
if (std::filesystem::exists(fullName)) {
|
||||
// Read JSON file content into object
|
||||
std::ifstream i(fullName);
|
||||
try {
|
||||
i >> json;
|
||||
} catch (nlohmann::json::exception& e) {
|
||||
sif::warning << "Reading JSON file failed with error " << e.what() << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
return HasFileSystemIF::FILE_DOES_NOT_EXIST;
|
||||
@ -19,7 +24,12 @@ ReturnValue_t NVMParameterBase::readJsonFile() {
|
||||
|
||||
ReturnValue_t NVMParameterBase::writeJsonFile() {
|
||||
std::ofstream o(fullName);
|
||||
try {
|
||||
o << std::setw(4) << json << std::endl;
|
||||
} catch (nlohmann::json::exception& e) {
|
||||
sif::warning << "Writing JSON file failed with error " << e.what() << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user