Skip to content

Commit

Permalink
Capture exceptions by const& in docs. (#4099)
Browse files Browse the repository at this point in the history
  • Loading branch information
iwanders authored Sep 23, 2023
1 parent 1ce29fa commit aa87ab8
Show file tree
Hide file tree
Showing 31 changed files with 49 additions and 49 deletions.
12 changes: 6 additions & 6 deletions docs/examples/at__json_pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand All @@ -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';
}
Expand All @@ -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';
}
Expand All @@ -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';
}
Expand All @@ -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';
}
Expand All @@ -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';
}
Expand Down
10 changes: 5 additions & 5 deletions docs/examples/at__json_pointer_const.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand All @@ -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';
}
Expand All @@ -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';
}
Expand All @@ -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';
}
Expand All @@ -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';
}
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/at__keytype.c++17.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand All @@ -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';
}
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/at__keytype_const.c++17.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand All @@ -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';
}
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/at__object_t_key_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand All @@ -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';
}
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/at__object_t_key_type_const.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand All @@ -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';
}
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/at__size_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand All @@ -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';
}
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/at__size_type_const.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand All @@ -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';
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/back.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/basic_json__InputIt_InputIt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/cbor_tag_handler_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/contains__json_pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand All @@ -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';
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/diagnostics_extended.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/diagnostics_standard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/error_handler_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/get_ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int main()
{
auto r3 = value.get_ref<json::number_float_t&>();
}
catch (json::type_error& ex)
catch (const json::type_error& ex)
{
std::cout << ex.what() << '\n';
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/invalid_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/json_pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand All @@ -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';
}
Expand All @@ -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';
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/nlohmann_define_type_intrusive_explicit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int main()
{
auto p3 = j3.template get<ns::person>();
}
catch (json::exception& e)
catch (const json::exception& e)
{
std::cout << "deserialization failed: " << e.what() << std::endl;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/nlohmann_define_type_intrusive_macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int main()
{
auto p3 = j3.template get<ns::person>();
}
catch (json::exception& e)
catch (const json::exception& e)
{
std::cout << "deserialization failed: " << e.what() << std::endl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main()
{
auto p3 = j3.template get<ns::person>();
}
catch (json::exception& e)
catch (const json::exception& e)
{
std::cout << "deserialization failed: " << e.what() << std::endl;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/nlohmann_define_type_non_intrusive_macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main()
{
auto p3 = j3.template get<ns::person>();
}
catch (json::exception& e)
catch (const json::exception& e)
{
std::cout << "deserialization failed: " << e.what() << std::endl;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/operator__ValueType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
Loading

0 comments on commit aa87ab8

Please sign in to comment.