Skip to content
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

Capture exceptions by const& in docs. #4099

Merged
merged 1 commit into from
Sep 23, 2023

Conversation

iwanders
Copy link
Contributor

@iwanders iwanders commented Aug 4, 2023

Hi,

The core guidelines recommend catching by const& for all but very small value types. One of my colleagues filed a PR internally with catch (nlohmann::json::type_error& e), instead of catch (const nlohmann::json::type_error& e), with the explanation that it was copied from the documentation. The error here holds a string however, so it is not a simple type that fits in a single register, I think const & is appropriate. This PR updates the documentation's exception catching to be all const.

Automated replace performed with the following command:

find ./ -type f -name *.cpp -print0 | xargs -0 sed -i -e 's|catch (json|catch (const json|g'

Pull request checklist

Read the Contribution Guidelines for detailed information.

  • Changes are described in the pull request, or an existing issue is referenced.
  • The test suite compiles and runs without error.
  • Code coverage is 100%. Test cases can be added by editing the test suite.
  • The source code is amalgamated; that is, after making changes to the sources in the include/nlohmann directory, run make amalgamate to create the single-header files single_include/nlohmann/json.hpp and single_include/nlohmann/json_fwd.hpp. The whole process is described here.

Performed with:
```
find ./ -type f -name *.cpp -print0 | xargs -0 sed -i -e 's|catch (json|catch (const json|g'
```
@coveralls
Copy link

Coverage Status

coverage: 100.0%. remained the same when pulling e5fb288 on iwanders:catch-by-const-in-docs into 5d27543 on nlohmann:develop.

@iwanders
Copy link
Contributor Author

iwanders commented Aug 4, 2023

Failure here seems unrelated to these changes?

Use of uninitialized value $Clang in concatenation (.) or string at /usr/bin/scan-build line 1859.
sh: 1: : Permission denied
scan-build: error: Cannot find an executable 'clang' relative to scan-build. Consider using --use-analyzer to pick a version of 'clang' to use for static analysis.
gmake[3]: *** [CMakeFiles/ci_clang_analyze.dir/build.make:72: CMakeFiles/ci_clang_analyze] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:1143: CMakeFiles/ci_clang_analyze.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:1150: CMakeFiles/ci_clang_analyze.dir/rule] Error 2
gmake: *** [Makefile:465: ci_clang_analyze] Error 2
Error: Process completed with exit code 2.

Copy link
Owner

@nlohmann nlohmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@nlohmann nlohmann added this to the Release 3.11.3 milestone Sep 23, 2023
@nlohmann nlohmann merged commit aa87ab8 into nlohmann:develop Sep 23, 2023
106 of 109 checks passed
@nlohmann
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants