Skip to content

Commit aa87ab8

Browse files
authored
Capture exceptions by const& in docs. (#4099)
1 parent 1ce29fa commit aa87ab8

31 files changed

Lines changed: 49 additions & 49 deletions

docs/examples/at__json_pointer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int main()
4141
// try to use an array index with leading '0'
4242
json::reference ref = j.at("/array/01"_json_pointer);
4343
}
44-
catch (json::parse_error& e)
44+
catch (const json::parse_error& e)
4545
{
4646
std::cout << e.what() << '\n';
4747
}
@@ -52,7 +52,7 @@ int main()
5252
// try to use an array index that is not a number
5353
json::reference ref = j.at("/array/one"_json_pointer);
5454
}
55-
catch (json::parse_error& e)
55+
catch (const json::parse_error& e)
5656
{
5757
std::cout << e.what() << '\n';
5858
}
@@ -63,7 +63,7 @@ int main()
6363
// try to use an invalid array index
6464
json::reference ref = j.at("/array/4"_json_pointer);
6565
}
66-
catch (json::out_of_range& e)
66+
catch (const json::out_of_range& e)
6767
{
6868
std::cout << e.what() << '\n';
6969
}
@@ -74,7 +74,7 @@ int main()
7474
// try to use the array index '-'
7575
json::reference ref = j.at("/array/-"_json_pointer);
7676
}
77-
catch (json::out_of_range& e)
77+
catch (const json::out_of_range& e)
7878
{
7979
std::cout << e.what() << '\n';
8080
}
@@ -85,7 +85,7 @@ int main()
8585
// try to use a JSON pointer to a nonexistent object key
8686
json::const_reference ref = j.at("/foo"_json_pointer);
8787
}
88-
catch (json::out_of_range& e)
88+
catch (const json::out_of_range& e)
8989
{
9090
std::cout << e.what() << '\n';
9191
}
@@ -96,7 +96,7 @@ int main()
9696
// try to use a JSON pointer that cannot be resolved
9797
json::reference ref = j.at("/number/foo"_json_pointer);
9898
}
99-
catch (json::out_of_range& e)
99+
catch (const json::out_of_range& e)
100100
{
101101
std::cout << e.what() << '\n';
102102
}

docs/examples/at__json_pointer_const.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ int main()
2929
// try to use an array index that is not a number
3030
json::const_reference ref = j.at("/array/one"_json_pointer);
3131
}
32-
catch (json::parse_error& e)
32+
catch (const json::parse_error& e)
3333
{
3434
std::cout << e.what() << '\n';
3535
}
@@ -40,7 +40,7 @@ int main()
4040
// try to use an invalid array index
4141
json::const_reference ref = j.at("/array/4"_json_pointer);
4242
}
43-
catch (json::out_of_range& e)
43+
catch (const json::out_of_range& e)
4444
{
4545
std::cout << e.what() << '\n';
4646
}
@@ -51,7 +51,7 @@ int main()
5151
// try to use the array index '-'
5252
json::const_reference ref = j.at("/array/-"_json_pointer);
5353
}
54-
catch (json::out_of_range& e)
54+
catch (const json::out_of_range& e)
5555
{
5656
std::cout << e.what() << '\n';
5757
}
@@ -62,7 +62,7 @@ int main()
6262
// try to use a JSON pointer to a nonexistent object key
6363
json::const_reference ref = j.at("/foo"_json_pointer);
6464
}
65-
catch (json::out_of_range& e)
65+
catch (const json::out_of_range& e)
6666
{
6767
std::cout << e.what() << '\n';
6868
}
@@ -73,7 +73,7 @@ int main()
7373
// try to use a JSON pointer that cannot be resolved
7474
json::const_reference ref = j.at("/number/foo"_json_pointer);
7575
}
76-
catch (json::out_of_range& e)
76+
catch (const json::out_of_range& e)
7777
{
7878
std::cout << e.what() << '\n';
7979
}

docs/examples/at__keytype.c++17.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int main()
3131
json str = "I am a string";
3232
str.at("the good"sv) = "Another string";
3333
}
34-
catch (json::type_error& e)
34+
catch (const json::type_error& e)
3535
{
3636
std::cout << e.what() << '\n';
3737
}
@@ -42,7 +42,7 @@ int main()
4242
// try to write at a nonexisting key using string_view
4343
object.at("the fast"sv) = "il rapido";
4444
}
45-
catch (json::out_of_range& e)
45+
catch (const json::out_of_range& e)
4646
{
4747
std::cout << e.what() << '\n';
4848
}

docs/examples/at__keytype_const.c++17.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int main()
2525
const json str = "I am a string";
2626
std::cout << str.at("the good"sv) << '\n';
2727
}
28-
catch (json::type_error& e)
28+
catch (const json::type_error& e)
2929
{
3030
std::cout << e.what() << '\n';
3131
}
@@ -36,7 +36,7 @@ int main()
3636
// try to read from a nonexisting key using string_view
3737
std::cout << object.at("the fast"sv) << '\n';
3838
}
39-
catch (json::out_of_range)
39+
catch (const json::out_of_range)
4040
{
4141
std::cout << "out of range" << '\n';
4242
}

docs/examples/at__object_t_key_type.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ int main()
2929
json str = "I am a string";
3030
str.at("the good") = "Another string";
3131
}
32-
catch (json::type_error& e)
32+
catch (const json::type_error& e)
3333
{
3434
std::cout << e.what() << '\n';
3535
}
@@ -40,7 +40,7 @@ int main()
4040
// try to write at a nonexisting key
4141
object.at("the fast") = "il rapido";
4242
}
43-
catch (json::out_of_range& e)
43+
catch (const json::out_of_range& e)
4444
{
4545
std::cout << e.what() << '\n';
4646
}

docs/examples/at__object_t_key_type_const.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int main()
2323
const json str = "I am a string";
2424
std::cout << str.at("the good") << '\n';
2525
}
26-
catch (json::type_error& e)
26+
catch (const json::type_error& e)
2727
{
2828
std::cout << e.what() << '\n';
2929
}
@@ -34,7 +34,7 @@ int main()
3434
// try to read from a nonexisting key
3535
std::cout << object.at("the fast") << '\n';
3636
}
37-
catch (json::out_of_range)
37+
catch (const json::out_of_range)
3838
{
3939
std::cout << "out of range" << '\n';
4040
}

docs/examples/at__size_type.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int main()
2424
json str = "I am a string";
2525
str.at(0) = "Another string";
2626
}
27-
catch (json::type_error& e)
27+
catch (const json::type_error& e)
2828
{
2929
std::cout << e.what() << '\n';
3030
}
@@ -35,7 +35,7 @@ int main()
3535
// try to write beyond the array limit
3636
array.at(5) = "sixth";
3737
}
38-
catch (json::out_of_range& e)
38+
catch (const json::out_of_range& e)
3939
{
4040
std::cout << e.what() << '\n';
4141
}

docs/examples/at__size_type_const.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ int main()
1818
const json str = "I am a string";
1919
std::cout << str.at(0) << '\n';
2020
}
21-
catch (json::type_error& e)
21+
catch (const json::type_error& e)
2222
{
2323
std::cout << e.what() << '\n';
2424
}
@@ -29,7 +29,7 @@ int main()
2929
// try to read beyond the array limit
3030
std::cout << array.at(5) << '\n';
3131
}
32-
catch (json::out_of_range& e)
32+
catch (const json::out_of_range& e)
3333
{
3434
std::cout << e.what() << '\n';
3535
}

docs/examples/back.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int main()
3131
json j_null;
3232
j_null.back();
3333
}
34-
catch (json::invalid_iterator& e)
34+
catch (const json::invalid_iterator& e)
3535
{
3636
std::cout << e.what() << '\n';
3737
}

docs/examples/basic_json__InputIt_InputIt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int main()
2525
{
2626
json j_invalid(j_number.begin() + 1, j_number.end());
2727
}
28-
catch (json::invalid_iterator& e)
28+
catch (const json::invalid_iterator& e)
2929
{
3030
std::cout << e.what() << '\n';
3131
}

0 commit comments

Comments
 (0)