other_error.cpp 663 B

1234567891011121314151617181920212223242526272829
  1. #include <iostream>
  2. #include <nlohmann/json.hpp>
  3. using json = nlohmann::json;
  4. int main()
  5. {
  6. try
  7. {
  8. // executing a failing JSON Patch operation
  9. json value = R"({
  10. "best_biscuit": {
  11. "name": "Oreo"
  12. }
  13. })"_json;
  14. json patch = R"([{
  15. "op": "test",
  16. "path": "/best_biscuit/name",
  17. "value": "Choco Leibniz"
  18. }])"_json;
  19. value.patch(patch);
  20. }
  21. catch (json::other_error& e)
  22. {
  23. // output exception information
  24. std::cout << "message: " << e.what() << '\n'
  25. << "exception id: " << e.id << std::endl;
  26. }
  27. }