json/docs/examples/exception.cpp

21 lines
438 B
C++
Raw Normal View History

2017-08-29 23:46:26 +02:00
#include <iostream>
#include <nlohmann/json.hpp>
2017-08-29 23:46:26 +02:00
using json = nlohmann::json;
int main()
{
try
{
// calling at() for a non-existing key
json j = {{"foo", "bar"}};
json k = j.at("non-existing");
}
catch (const json::exception& e)
2017-08-29 23:46:26 +02:00
{
// output exception information
std::cout << "message: " << e.what() << '\n'
<< "exception id: " << e.id << std::endl;
}
}