From aa87ab8b406889f34c337d9564d4ba04537b9a74 Mon Sep 17 00:00:00 2001 From: Ivor Wanders Date: Sat, 23 Sep 2023 11:19:50 -0400 Subject: [PATCH] Capture exceptions by const& in docs. (#4099) --- docs/examples/at__json_pointer.cpp | 12 ++++++------ docs/examples/at__json_pointer_const.cpp | 10 +++++----- docs/examples/at__keytype.c++17.cpp | 4 ++-- docs/examples/at__keytype_const.c++17.cpp | 4 ++-- docs/examples/at__object_t_key_type.cpp | 4 ++-- docs/examples/at__object_t_key_type_const.cpp | 4 ++-- docs/examples/at__size_type.cpp | 4 ++-- docs/examples/at__size_type_const.cpp | 4 ++-- docs/examples/back.cpp | 2 +- docs/examples/basic_json__InputIt_InputIt.cpp | 2 +- docs/examples/cbor_tag_handler_t.cpp | 2 +- docs/examples/contains__json_pointer.cpp | 4 ++-- docs/examples/diagnostics_extended.cpp | 2 +- docs/examples/diagnostics_standard.cpp | 2 +- docs/examples/dump.cpp | 2 +- docs/examples/error_handler_t.cpp | 2 +- docs/examples/exception.cpp | 2 +- docs/examples/get_ref.cpp | 2 +- docs/examples/invalid_iterator.cpp | 2 +- docs/examples/json_pointer.cpp | 6 +++--- .../nlohmann_define_type_intrusive_explicit.cpp | 2 +- .../nlohmann_define_type_intrusive_macro.cpp | 2 +- .../nlohmann_define_type_non_intrusive_explicit.cpp | 2 +- .../nlohmann_define_type_non_intrusive_macro.cpp | 2 +- docs/examples/object.cpp | 2 +- docs/examples/operator__ValueType.cpp | 2 +- docs/examples/other_error.cpp | 2 +- docs/examples/out_of_range.cpp | 2 +- docs/examples/parse__allow_exceptions.cpp | 2 +- docs/examples/parse_error.cpp | 2 +- docs/examples/type_error.cpp | 2 +- 31 files changed, 49 insertions(+), 49 deletions(-) diff --git a/docs/examples/at__json_pointer.cpp b/docs/examples/at__json_pointer.cpp index 9cb6cf9a2e..15e91433d6 100644 --- a/docs/examples/at__json_pointer.cpp +++ b/docs/examples/at__json_pointer.cpp @@ -41,7 +41,7 @@ int main() // try to use an array index with leading '0' json::reference ref = j.at("/array/01"_json_pointer); } - catch (json::parse_error& e) + catch (const json::parse_error& e) { std::cout << e.what() << '\n'; } @@ -52,7 +52,7 @@ int main() // try to use an array index that is not a number json::reference ref = j.at("/array/one"_json_pointer); } - catch (json::parse_error& e) + catch (const json::parse_error& e) { std::cout << e.what() << '\n'; } @@ -63,7 +63,7 @@ int main() // try to use an invalid array index json::reference ref = j.at("/array/4"_json_pointer); } - catch (json::out_of_range& e) + catch (const json::out_of_range& e) { std::cout << e.what() << '\n'; } @@ -74,7 +74,7 @@ int main() // try to use the array index '-' json::reference ref = j.at("/array/-"_json_pointer); } - catch (json::out_of_range& e) + catch (const json::out_of_range& e) { std::cout << e.what() << '\n'; } @@ -85,7 +85,7 @@ int main() // try to use a JSON pointer to a nonexistent object key json::const_reference ref = j.at("/foo"_json_pointer); } - catch (json::out_of_range& e) + catch (const json::out_of_range& e) { std::cout << e.what() << '\n'; } @@ -96,7 +96,7 @@ int main() // try to use a JSON pointer that cannot be resolved json::reference ref = j.at("/number/foo"_json_pointer); } - catch (json::out_of_range& e) + catch (const json::out_of_range& e) { std::cout << e.what() << '\n'; } diff --git a/docs/examples/at__json_pointer_const.cpp b/docs/examples/at__json_pointer_const.cpp index f049bd8d9e..ab026e0781 100644 --- a/docs/examples/at__json_pointer_const.cpp +++ b/docs/examples/at__json_pointer_const.cpp @@ -29,7 +29,7 @@ int main() // try to use an array index that is not a number json::const_reference ref = j.at("/array/one"_json_pointer); } - catch (json::parse_error& e) + catch (const json::parse_error& e) { std::cout << e.what() << '\n'; } @@ -40,7 +40,7 @@ int main() // try to use an invalid array index json::const_reference ref = j.at("/array/4"_json_pointer); } - catch (json::out_of_range& e) + catch (const json::out_of_range& e) { std::cout << e.what() << '\n'; } @@ -51,7 +51,7 @@ int main() // try to use the array index '-' json::const_reference ref = j.at("/array/-"_json_pointer); } - catch (json::out_of_range& e) + catch (const json::out_of_range& e) { std::cout << e.what() << '\n'; } @@ -62,7 +62,7 @@ int main() // try to use a JSON pointer to a nonexistent object key json::const_reference ref = j.at("/foo"_json_pointer); } - catch (json::out_of_range& e) + catch (const json::out_of_range& e) { std::cout << e.what() << '\n'; } @@ -73,7 +73,7 @@ int main() // try to use a JSON pointer that cannot be resolved json::const_reference ref = j.at("/number/foo"_json_pointer); } - catch (json::out_of_range& e) + catch (const json::out_of_range& e) { std::cout << e.what() << '\n'; } diff --git a/docs/examples/at__keytype.c++17.cpp b/docs/examples/at__keytype.c++17.cpp index e0d9b9e7b4..032506acd7 100644 --- a/docs/examples/at__keytype.c++17.cpp +++ b/docs/examples/at__keytype.c++17.cpp @@ -31,7 +31,7 @@ int main() json str = "I am a string"; str.at("the good"sv) = "Another string"; } - catch (json::type_error& e) + catch (const json::type_error& e) { std::cout << e.what() << '\n'; } @@ -42,7 +42,7 @@ int main() // try to write at a nonexisting key using string_view object.at("the fast"sv) = "il rapido"; } - catch (json::out_of_range& e) + catch (const json::out_of_range& e) { std::cout << e.what() << '\n'; } diff --git a/docs/examples/at__keytype_const.c++17.cpp b/docs/examples/at__keytype_const.c++17.cpp index 1f32f23a51..b08cd17b5c 100644 --- a/docs/examples/at__keytype_const.c++17.cpp +++ b/docs/examples/at__keytype_const.c++17.cpp @@ -25,7 +25,7 @@ int main() const json str = "I am a string"; std::cout << str.at("the good"sv) << '\n'; } - catch (json::type_error& e) + catch (const json::type_error& e) { std::cout << e.what() << '\n'; } @@ -36,7 +36,7 @@ int main() // try to read from a nonexisting key using string_view std::cout << object.at("the fast"sv) << '\n'; } - catch (json::out_of_range) + catch (const json::out_of_range) { std::cout << "out of range" << '\n'; } diff --git a/docs/examples/at__object_t_key_type.cpp b/docs/examples/at__object_t_key_type.cpp index 3a59d1a504..e1f33cecab 100644 --- a/docs/examples/at__object_t_key_type.cpp +++ b/docs/examples/at__object_t_key_type.cpp @@ -29,7 +29,7 @@ int main() json str = "I am a string"; str.at("the good") = "Another string"; } - catch (json::type_error& e) + catch (const json::type_error& e) { std::cout << e.what() << '\n'; } @@ -40,7 +40,7 @@ int main() // try to write at a nonexisting key object.at("the fast") = "il rapido"; } - catch (json::out_of_range& e) + catch (const json::out_of_range& e) { std::cout << e.what() << '\n'; } diff --git a/docs/examples/at__object_t_key_type_const.cpp b/docs/examples/at__object_t_key_type_const.cpp index f41bab61a0..b37bbd489c 100644 --- a/docs/examples/at__object_t_key_type_const.cpp +++ b/docs/examples/at__object_t_key_type_const.cpp @@ -23,7 +23,7 @@ int main() const json str = "I am a string"; std::cout << str.at("the good") << '\n'; } - catch (json::type_error& e) + catch (const json::type_error& e) { std::cout << e.what() << '\n'; } @@ -34,7 +34,7 @@ int main() // try to read from a nonexisting key std::cout << object.at("the fast") << '\n'; } - catch (json::out_of_range) + catch (const json::out_of_range) { std::cout << "out of range" << '\n'; } diff --git a/docs/examples/at__size_type.cpp b/docs/examples/at__size_type.cpp index 001b51d59f..6527c6b16d 100644 --- a/docs/examples/at__size_type.cpp +++ b/docs/examples/at__size_type.cpp @@ -24,7 +24,7 @@ int main() json str = "I am a string"; str.at(0) = "Another string"; } - catch (json::type_error& e) + catch (const json::type_error& e) { std::cout << e.what() << '\n'; } @@ -35,7 +35,7 @@ int main() // try to write beyond the array limit array.at(5) = "sixth"; } - catch (json::out_of_range& e) + catch (const json::out_of_range& e) { std::cout << e.what() << '\n'; } diff --git a/docs/examples/at__size_type_const.cpp b/docs/examples/at__size_type_const.cpp index e2bebf7ecb..2080387a39 100644 --- a/docs/examples/at__size_type_const.cpp +++ b/docs/examples/at__size_type_const.cpp @@ -18,7 +18,7 @@ int main() const json str = "I am a string"; std::cout << str.at(0) << '\n'; } - catch (json::type_error& e) + catch (const json::type_error& e) { std::cout << e.what() << '\n'; } @@ -29,7 +29,7 @@ int main() // try to read beyond the array limit std::cout << array.at(5) << '\n'; } - catch (json::out_of_range& e) + catch (const json::out_of_range& e) { std::cout << e.what() << '\n'; } diff --git a/docs/examples/back.cpp b/docs/examples/back.cpp index 1439a8218c..45342db139 100644 --- a/docs/examples/back.cpp +++ b/docs/examples/back.cpp @@ -31,7 +31,7 @@ int main() json j_null; j_null.back(); } - catch (json::invalid_iterator& e) + catch (const json::invalid_iterator& e) { std::cout << e.what() << '\n'; } diff --git a/docs/examples/basic_json__InputIt_InputIt.cpp b/docs/examples/basic_json__InputIt_InputIt.cpp index ed5aff9a83..dec693c80c 100644 --- a/docs/examples/basic_json__InputIt_InputIt.cpp +++ b/docs/examples/basic_json__InputIt_InputIt.cpp @@ -25,7 +25,7 @@ int main() { json j_invalid(j_number.begin() + 1, j_number.end()); } - catch (json::invalid_iterator& e) + catch (const json::invalid_iterator& e) { std::cout << e.what() << '\n'; } diff --git a/docs/examples/cbor_tag_handler_t.cpp b/docs/examples/cbor_tag_handler_t.cpp index 79052c7a0d..38d168ca89 100644 --- a/docs/examples/cbor_tag_handler_t.cpp +++ b/docs/examples/cbor_tag_handler_t.cpp @@ -13,7 +13,7 @@ int main() { auto b_throw_on_tag = json::from_cbor(vec, true, true, json::cbor_tag_handler_t::error); } - catch (json::parse_error& e) + catch (const json::parse_error& e) { std::cout << e.what() << std::endl; } diff --git a/docs/examples/contains__json_pointer.cpp b/docs/examples/contains__json_pointer.cpp index f9de546b5d..14d8514b41 100644 --- a/docs/examples/contains__json_pointer.cpp +++ b/docs/examples/contains__json_pointer.cpp @@ -26,7 +26,7 @@ int main() // try to use an array index with leading '0' j.contains("/array/01"_json_pointer); } - catch (json::parse_error& e) + catch (const json::parse_error& e) { std::cout << e.what() << '\n'; } @@ -36,7 +36,7 @@ int main() // try to use an array index that is not a number j.contains("/array/one"_json_pointer); } - catch (json::parse_error& e) + catch (const json::parse_error& e) { std::cout << e.what() << '\n'; } diff --git a/docs/examples/diagnostics_extended.cpp b/docs/examples/diagnostics_extended.cpp index f4c43f05e6..3b9f484b7e 100644 --- a/docs/examples/diagnostics_extended.cpp +++ b/docs/examples/diagnostics_extended.cpp @@ -15,7 +15,7 @@ int main() { int housenumber = j["address"]["housenumber"]; } - catch (json::exception& e) + catch (const json::exception& e) { std::cout << e.what() << '\n'; } diff --git a/docs/examples/diagnostics_standard.cpp b/docs/examples/diagnostics_standard.cpp index 575c409eb6..eae61a4a77 100644 --- a/docs/examples/diagnostics_standard.cpp +++ b/docs/examples/diagnostics_standard.cpp @@ -13,7 +13,7 @@ int main() { int housenumber = j["address"]["housenumber"]; } - catch (json::exception& e) + catch (const json::exception& e) { std::cout << e.what() << '\n'; } diff --git a/docs/examples/dump.cpp b/docs/examples/dump.cpp index eb2d71f0ee..009c95fd71 100644 --- a/docs/examples/dump.cpp +++ b/docs/examples/dump.cpp @@ -35,7 +35,7 @@ int main() { std::cout << j_invalid.dump() << std::endl; } - catch (json::type_error& e) + catch (const json::type_error& e) { std::cout << e.what() << std::endl; } diff --git a/docs/examples/error_handler_t.cpp b/docs/examples/error_handler_t.cpp index add3f3b2d7..b4718d7e68 100644 --- a/docs/examples/error_handler_t.cpp +++ b/docs/examples/error_handler_t.cpp @@ -11,7 +11,7 @@ int main() { std::cout << j_invalid.dump() << std::endl; } - catch (json::type_error& e) + catch (const json::type_error& e) { std::cout << e.what() << std::endl; } diff --git a/docs/examples/exception.cpp b/docs/examples/exception.cpp index 82696e6142..3e5a23b3c2 100644 --- a/docs/examples/exception.cpp +++ b/docs/examples/exception.cpp @@ -11,7 +11,7 @@ int main() json j = {{"foo", "bar"}}; json k = j.at("non-existing"); } - catch (json::exception& e) + catch (const json::exception& e) { // output exception information std::cout << "message: " << e.what() << '\n' diff --git a/docs/examples/get_ref.cpp b/docs/examples/get_ref.cpp index ab25946bb3..0183a65377 100644 --- a/docs/examples/get_ref.cpp +++ b/docs/examples/get_ref.cpp @@ -20,7 +20,7 @@ int main() { auto r3 = value.get_ref(); } - catch (json::type_error& ex) + catch (const json::type_error& ex) { std::cout << ex.what() << '\n'; } diff --git a/docs/examples/invalid_iterator.cpp b/docs/examples/invalid_iterator.cpp index 5d3e622e64..ecde12e620 100644 --- a/docs/examples/invalid_iterator.cpp +++ b/docs/examples/invalid_iterator.cpp @@ -12,7 +12,7 @@ int main() json::iterator it = j.begin(); auto k = it.key(); } - catch (json::invalid_iterator& e) + catch (const json::invalid_iterator& e) { // output exception information std::cout << "message: " << e.what() << '\n' diff --git a/docs/examples/json_pointer.cpp b/docs/examples/json_pointer.cpp index 75b9717584..8705cf4982 100644 --- a/docs/examples/json_pointer.cpp +++ b/docs/examples/json_pointer.cpp @@ -20,7 +20,7 @@ int main() { json::json_pointer p9("foo"); } - catch (json::parse_error& e) + catch (const json::parse_error& e) { std::cout << e.what() << '\n'; } @@ -30,7 +30,7 @@ int main() { json::json_pointer p10("/foo/~"); } - catch (json::parse_error& e) + catch (const json::parse_error& e) { std::cout << e.what() << '\n'; } @@ -40,7 +40,7 @@ int main() { json::json_pointer p11("/foo/~3"); } - catch (json::parse_error& e) + catch (const json::parse_error& e) { std::cout << e.what() << '\n'; } diff --git a/docs/examples/nlohmann_define_type_intrusive_explicit.cpp b/docs/examples/nlohmann_define_type_intrusive_explicit.cpp index f2d6812cb0..de79bd37c9 100644 --- a/docs/examples/nlohmann_define_type_intrusive_explicit.cpp +++ b/docs/examples/nlohmann_define_type_intrusive_explicit.cpp @@ -53,7 +53,7 @@ int main() { auto p3 = j3.template get(); } - catch (json::exception& e) + catch (const json::exception& e) { std::cout << "deserialization failed: " << e.what() << std::endl; } diff --git a/docs/examples/nlohmann_define_type_intrusive_macro.cpp b/docs/examples/nlohmann_define_type_intrusive_macro.cpp index 9c020689b8..4ecd4294fc 100644 --- a/docs/examples/nlohmann_define_type_intrusive_macro.cpp +++ b/docs/examples/nlohmann_define_type_intrusive_macro.cpp @@ -41,7 +41,7 @@ int main() { auto p3 = j3.template get(); } - catch (json::exception& e) + catch (const json::exception& e) { std::cout << "deserialization failed: " << e.what() << std::endl; } diff --git a/docs/examples/nlohmann_define_type_non_intrusive_explicit.cpp b/docs/examples/nlohmann_define_type_non_intrusive_explicit.cpp index b3040adc61..a31a7eb8ff 100644 --- a/docs/examples/nlohmann_define_type_non_intrusive_explicit.cpp +++ b/docs/examples/nlohmann_define_type_non_intrusive_explicit.cpp @@ -46,7 +46,7 @@ int main() { auto p3 = j3.template get(); } - catch (json::exception& e) + catch (const json::exception& e) { std::cout << "deserialization failed: " << e.what() << std::endl; } diff --git a/docs/examples/nlohmann_define_type_non_intrusive_macro.cpp b/docs/examples/nlohmann_define_type_non_intrusive_macro.cpp index 2c76830d82..d11691b701 100644 --- a/docs/examples/nlohmann_define_type_non_intrusive_macro.cpp +++ b/docs/examples/nlohmann_define_type_non_intrusive_macro.cpp @@ -34,7 +34,7 @@ int main() { auto p3 = j3.template get(); } - catch (json::exception& e) + catch (const json::exception& e) { std::cout << "deserialization failed: " << e.what() << std::endl; } diff --git a/docs/examples/object.cpp b/docs/examples/object.cpp index 733b89b530..ad167d4af5 100644 --- a/docs/examples/object.cpp +++ b/docs/examples/object.cpp @@ -21,7 +21,7 @@ int main() // can only create an object from a list of pairs json j_invalid_object = json::object({{ "one", 1, 2 }}); } - catch (json::type_error& e) + catch (const json::type_error& e) { std::cout << e.what() << '\n'; } diff --git a/docs/examples/operator__ValueType.cpp b/docs/examples/operator__ValueType.cpp index 66fcf310e5..e8a1d349dd 100644 --- a/docs/examples/operator__ValueType.cpp +++ b/docs/examples/operator__ValueType.cpp @@ -53,7 +53,7 @@ int main() { bool v1 = json_types["string"]; } - catch (json::type_error& e) + catch (const json::type_error& e) { std::cout << e.what() << '\n'; } diff --git a/docs/examples/other_error.cpp b/docs/examples/other_error.cpp index 99c4be70e6..56aa8ae6b1 100644 --- a/docs/examples/other_error.cpp +++ b/docs/examples/other_error.cpp @@ -21,7 +21,7 @@ int main() }])"_json; value.patch(patch); } - catch (json::other_error& e) + catch (const json::other_error& e) { // output exception information std::cout << "message: " << e.what() << '\n' diff --git a/docs/examples/out_of_range.cpp b/docs/examples/out_of_range.cpp index e7116408a9..03282082de 100644 --- a/docs/examples/out_of_range.cpp +++ b/docs/examples/out_of_range.cpp @@ -11,7 +11,7 @@ int main() json j = {1, 2, 3, 4}; j.at(4) = 10; } - catch (json::out_of_range& e) + catch (const json::out_of_range& e) { // output exception information std::cout << "message: " << e.what() << '\n' diff --git a/docs/examples/parse__allow_exceptions.cpp b/docs/examples/parse__allow_exceptions.cpp index 82449a526a..f396c347ea 100644 --- a/docs/examples/parse__allow_exceptions.cpp +++ b/docs/examples/parse__allow_exceptions.cpp @@ -17,7 +17,7 @@ int main() { json j = json::parse(text); } - catch (json::parse_error& e) + catch (const json::parse_error& e) { std::cout << e.what() << std::endl; } diff --git a/docs/examples/parse_error.cpp b/docs/examples/parse_error.cpp index 9b27b58fab..ce15ebe22c 100644 --- a/docs/examples/parse_error.cpp +++ b/docs/examples/parse_error.cpp @@ -10,7 +10,7 @@ int main() // parsing input with a syntax error json::parse("[1,2,3,]"); } - catch (json::parse_error& e) + catch (const json::parse_error& e) { // output exception information std::cout << "message: " << e.what() << '\n' diff --git a/docs/examples/type_error.cpp b/docs/examples/type_error.cpp index d4f18b1800..f520f40131 100644 --- a/docs/examples/type_error.cpp +++ b/docs/examples/type_error.cpp @@ -11,7 +11,7 @@ int main() json j = "string"; j.push_back("another string"); } - catch (json::type_error& e) + catch (const json::type_error& e) { // output exception information std::cout << "message: " << e.what() << '\n'