json/doc/examples/type_error.cpp

21 lines
427 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 push_back() on a string value
json j = "string";
j.push_back("another string");
}
catch (json::type_error& e)
{
// output exception information
std::cout << "message: " << e.what() << '\n'
<< "exception id: " << e.id << std::endl;
}
}