exception.cpp 432 B

1234567891011121314151617181920
  1. #include <iostream>
  2. #include <nlohmann/json.hpp>
  3. using json = nlohmann::json;
  4. int main()
  5. {
  6. try
  7. {
  8. // calling at() for a non-existing key
  9. json j = {{"foo", "bar"}};
  10. json k = j.at("non-existing");
  11. }
  12. catch (json::exception& e)
  13. {
  14. // output exception information
  15. std::cout << "message: " << e.what() << '\n'
  16. << "exception id: " << e.id << std::endl;
  17. }
  18. }