mirror of
https://github.com/nlohmann/json.git
synced 2025-07-06 06:42:33 +03:00
📝 more documentation for the new exceptions
This commit is contained in:
@ -5,7 +5,6 @@ using json = nlohmann::json;
|
||||
int main()
|
||||
{
|
||||
// create JSON values
|
||||
json j_null;
|
||||
json j_boolean = true;
|
||||
json j_number_integer = 17;
|
||||
json j_number_float = 23.42;
|
||||
@ -16,7 +15,6 @@ int main()
|
||||
json j_string = "Hello, world";
|
||||
|
||||
// call back()
|
||||
//std::cout << j_null.back() << '\n'; // would throw
|
||||
std::cout << j_boolean.back() << '\n';
|
||||
std::cout << j_number_integer.back() << '\n';
|
||||
std::cout << j_number_float.back() << '\n';
|
||||
@ -25,4 +23,15 @@ int main()
|
||||
std::cout << j_array.back() << '\n';
|
||||
//std::cout << j_array_empty.back() << '\n'; // undefined behavior
|
||||
std::cout << j_string.back() << '\n';
|
||||
|
||||
// back() called on a null value
|
||||
try
|
||||
{
|
||||
json j_null;
|
||||
j_null.back();
|
||||
}
|
||||
catch (json::invalid_iterator& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user