1#include <iostream>
2#include <nlohmann/json.hpp>
3
4using json = nlohmann::json;
5
6int main()
7{
8    try
9    {
10        // calling iterator::key() on non-object iterator
11        json j = "string";
12        json::iterator it = j.begin();
13        auto k = it.key();
14    }
15    catch (json::invalid_iterator& e)
16    {
17        // output exception information
18        std::cout << "message: " << e.what() << '\n'
19                  << "exception id: " << e.id << std::endl;
20    }
21}
22