Improving error handing when reading json config #885
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Without mandatory fields set, the previous code would hit many exceptions in the happy load case. Thus, instead of depending on exceptions to detect the existence of keys in the parsed json, this change optionals to check to see whether a key exists. This should improve performance* (no stack unrolling for the exception) as well as allows some try/catch blocks to be removed (simpler code.)
Another driver for this change was that 4913ae3 swapped ellipses in the
catch
statements forstd::exception
. On the surface this seems like a positive change and even follows compiler warning message recommendations, however for unknown reasons on some platformscatch (std::exception)
would catch theboost::property_tree::ptree_bad_path
exceptions thrown byget_child
, and on other platforms it wouldn't. Even though there is a proposal to revert that commit, reducing dependence on exceptions in favour of optionals obviates this issue.Not every try/catch block was removed here, simply the ones where there's no conceivable change of an exception being thrown. The blocks surrounding the streamstream converters, and map access were left just in case.
* Have not tested whether it does improve performance