out_of_range.cpp 412 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 an invalid index
  9. json j = {1, 2, 3, 4};
  10. j.at(4) = 10;
  11. }
  12. catch (json::out_of_range& e)
  13. {
  14. // output exception information
  15. std::cout << "message: " << e.what() << '\n'
  16. << "exception id: " << e.id << std::endl;
  17. }
  18. }