parse_error.cpp 457 B

1234567891011121314151617181920
  1. #include <iostream>
  2. #include <nlohmann/json.hpp>
  3. using json = nlohmann::json;
  4. int main()
  5. {
  6. try
  7. {
  8. // parsing input with a syntax error
  9. json::parse("[1,2,3,]");
  10. }
  11. catch (json::parse_error& e)
  12. {
  13. // output exception information
  14. std::cout << "message: " << e.what() << '\n'
  15. << "exception id: " << e.id << '\n'
  16. << "byte position of error: " << e.byte << std::endl;
  17. }
  18. }