Capture exceptions by const& in docs. (#4099)

pull/4161/head
Ivor Wanders 2023-09-23 11:19:50 -04:00 committed by GitHub
parent 1ce29fa22f
commit aa87ab8b40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 49 additions and 49 deletions

View File

@ -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';
}

View File

@ -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';
}

View File

@ -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';
}

View File

@ -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';
}

View File

@ -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';
}

View File

@ -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';
}

View File

@ -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';
}

View File

@ -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';
}

View File

@ -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';
}

View File

@ -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';
}

View File

@ -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;
}

View File

@ -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';
}

View File

@ -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';
}

View File

@ -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';
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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'

View File

@ -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';
}

View File

@ -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'

View File

@ -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';
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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';
}

View File

@ -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';
}

View File

@ -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'

View File

@ -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'

View File

@ -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;
}

View File

@ -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'

View File

@ -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'