Skip to content

Improving error handing when reading json config #885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kheaactua
Copy link
Contributor

@kheaactua kheaactua commented Apr 8, 2025

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 for std::exception. On the surface this seems like a positive change and even follows compiler warning message recommendations, however for unknown reasons on some platforms catch (std::exception) would catch the boost::property_tree::ptree_bad_path exceptions thrown by get_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

@kheaactua kheaactua changed the title Ignore CMakeUserPresets.json Improving error handing when reading json config Apr 8, 2025
@kheaactua kheaactua force-pushed the remove_config_exceptions branch 3 times, most recently from 61dbfad to 6a68bfe Compare April 8, 2025 19:53
@kheaactua kheaactua force-pushed the remove_config_exceptions branch from 6a68bfe to f08ca43 Compare April 8, 2025 20:06
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.)
@kheaactua kheaactua force-pushed the remove_config_exceptions branch from f08ca43 to 85542c0 Compare April 8, 2025 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant