Capture exceptions by const& in docs. by iwanders · Pull Request #4099 · nlohmann/json
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/nlohmanndirectory, runmake amalgamateto create the single-header filessingle_include/nlohmann/json.hppandsingle_include/nlohmann/json_fwd.hpp. The whole process is described here.