diff --git a/src/json.hpp b/src/json.hpp index 3ee57f6e9..54528175b 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -3734,7 +3734,7 @@ class basic_json @throw type_error.304 if the JSON value is not an object; example: `"cannot use at() with boolean"` - @throw std::out_of_range if the key @a key is is not stored in the object; + @throw out_of_range.403 if the key @a key is is not stored in the object; that is, `find(key) == end()`; example: `"key "the fast" not found"` @complexity Logarithmic in the size of the container. @@ -3760,7 +3760,7 @@ class basic_json JSON_CATCH (std::out_of_range&) { // create better exception explanation - JSON_THROW(std::out_of_range("key '" + key + "' not found")); + JSON_THROW(out_of_range(403, "key '" + key + "' not found")); } } else @@ -3781,7 +3781,7 @@ class basic_json @throw type_error.304 if the JSON value is not an object; example: `"cannot use at() with boolean"` - @throw std::out_of_range if the key @a key is is not stored in the object; + @throw out_of_range.403 if the key @a key is is not stored in the object; that is, `find(key) == end()`; example: `"key "the fast" not found"` @complexity Logarithmic in the size of the container. @@ -3807,7 +3807,7 @@ class basic_json JSON_CATCH (std::out_of_range&) { // create better exception explanation - JSON_THROW(std::out_of_range("key '" + key + "' not found")); + JSON_THROW(out_of_range(403, "key '" + key + "' not found")); } } else @@ -4154,7 +4154,7 @@ class basic_json @code {.cpp} try { return at(key); - } catch(std::out_of_range) { + } catch(out_of_range) { return default_value; } @endcode @@ -4233,7 +4233,7 @@ class basic_json @code {.cpp} try { return at(ptr); - } catch(std::out_of_range) { + } catch(out_of_range) { return default_value; } @endcode @@ -4276,7 +4276,7 @@ class basic_json { return ptr.get_checked(this); } - JSON_CATCH (std::out_of_range&) + JSON_CATCH (out_of_range&) { return default_value; } @@ -12746,9 +12746,9 @@ basic_json_parser_74: any case, the original value is not changed: the patch is applied to a copy of the value. - @throw std::out_of_range if a JSON pointer inside the patch could not - be resolved successfully in the current JSON value; example: `"key baz - not found"` + @throw out_of_range.403 if a JSON pointer inside the patch could not be + resolved successfully in the current JSON value; example: `"key baz not + found"` @throw invalid_argument if the JSON patch is malformed (e.g., mandatory attributes are missing); example: `"operation add must have member path"` @throw parse_error.104 if the JSON patch does not consist of an array of @@ -12888,7 +12888,7 @@ basic_json_parser_74: } else { - JSON_THROW(std::out_of_range("key '" + last_path + "' not found")); + JSON_THROW(out_of_range(403, "key '" + last_path + "' not found")); } } else if (parent.is_array()) @@ -13002,7 +13002,7 @@ basic_json_parser_74: // the "path" location must exist - use at() success = (result.at(ptr) == get_value("test", "value", false)); } - JSON_CATCH (std::out_of_range&) + JSON_CATCH (out_of_range&) { // ignore out of range errors: success remains false } diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index c02f6bf88..2bbff0fbf 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -3734,7 +3734,7 @@ class basic_json @throw type_error.304 if the JSON value is not an object; example: `"cannot use at() with boolean"` - @throw std::out_of_range if the key @a key is is not stored in the object; + @throw out_of_range.403 if the key @a key is is not stored in the object; that is, `find(key) == end()`; example: `"key "the fast" not found"` @complexity Logarithmic in the size of the container. @@ -3760,7 +3760,7 @@ class basic_json JSON_CATCH (std::out_of_range&) { // create better exception explanation - JSON_THROW(std::out_of_range("key '" + key + "' not found")); + JSON_THROW(out_of_range(403, "key '" + key + "' not found")); } } else @@ -3781,7 +3781,7 @@ class basic_json @throw type_error.304 if the JSON value is not an object; example: `"cannot use at() with boolean"` - @throw std::out_of_range if the key @a key is is not stored in the object; + @throw out_of_range.403 if the key @a key is is not stored in the object; that is, `find(key) == end()`; example: `"key "the fast" not found"` @complexity Logarithmic in the size of the container. @@ -3807,7 +3807,7 @@ class basic_json JSON_CATCH (std::out_of_range&) { // create better exception explanation - JSON_THROW(std::out_of_range("key '" + key + "' not found")); + JSON_THROW(out_of_range(403, "key '" + key + "' not found")); } } else @@ -4154,7 +4154,7 @@ class basic_json @code {.cpp} try { return at(key); - } catch(std::out_of_range) { + } catch(out_of_range) { return default_value; } @endcode @@ -4233,7 +4233,7 @@ class basic_json @code {.cpp} try { return at(ptr); - } catch(std::out_of_range) { + } catch(out_of_range) { return default_value; } @endcode @@ -4276,7 +4276,7 @@ class basic_json { return ptr.get_checked(this); } - JSON_CATCH (std::out_of_range&) + JSON_CATCH (out_of_range&) { return default_value; } @@ -11779,9 +11779,9 @@ class basic_json any case, the original value is not changed: the patch is applied to a copy of the value. - @throw std::out_of_range if a JSON pointer inside the patch could not - be resolved successfully in the current JSON value; example: `"key baz - not found"` + @throw out_of_range.403 if a JSON pointer inside the patch could not be + resolved successfully in the current JSON value; example: `"key baz not + found"` @throw invalid_argument if the JSON patch is malformed (e.g., mandatory attributes are missing); example: `"operation add must have member path"` @throw parse_error.104 if the JSON patch does not consist of an array of @@ -11921,7 +11921,7 @@ class basic_json } else { - JSON_THROW(std::out_of_range("key '" + last_path + "' not found")); + JSON_THROW(out_of_range(403, "key '" + last_path + "' not found")); } } else if (parent.is_array()) @@ -12035,7 +12035,7 @@ class basic_json // the "path" location must exist - use at() success = (result.at(ptr) == get_value("test", "value", false)); } - JSON_CATCH (std::out_of_range&) + JSON_CATCH (out_of_range&) { // ignore out of range errors: success remains false } diff --git a/test/src/unit-element_access2.cpp b/test/src/unit-element_access2.cpp index 4a066e709..3533bdcd9 100644 --- a/test/src/unit-element_access2.cpp +++ b/test/src/unit-element_access2.cpp @@ -63,10 +63,12 @@ TEST_CASE("element access 2") SECTION("access outside bounds") { - CHECK_THROWS_AS(j.at("foo"), std::out_of_range); - CHECK_THROWS_AS(j_const.at("foo"), std::out_of_range); - CHECK_THROWS_WITH(j.at("foo"), "key 'foo' not found"); - CHECK_THROWS_WITH(j_const.at("foo"), "key 'foo' not found"); + CHECK_THROWS_AS(j.at("foo"), json::out_of_range); + CHECK_THROWS_AS(j_const.at("foo"), json::out_of_range); + CHECK_THROWS_WITH(j.at("foo"), + "[json.exception.out_of_range.403] key 'foo' not found"); + CHECK_THROWS_WITH(j_const.at("foo"), + "[json.exception.out_of_range.403] key 'foo' not found"); } SECTION("access on non-object type") diff --git a/test/src/unit-json_patch.cpp b/test/src/unit-json_patch.cpp index feb7a154f..9c07aae61 100644 --- a/test/src/unit-json_patch.cpp +++ b/test/src/unit-json_patch.cpp @@ -75,8 +75,9 @@ TEST_CASE("JSON patch") json doc2 = R"({ "q": { "bar": 2 } })"_json; // because "a" does not exist. - CHECK_THROWS_AS(doc2.patch(patch), std::out_of_range); - CHECK_THROWS_WITH(doc2.patch(patch), "key 'a' not found"); + CHECK_THROWS_AS(doc2.patch(patch), json::out_of_range); + CHECK_THROWS_WITH(doc2.patch(patch), + "[json.exception.out_of_range.403] key 'a' not found"); } SECTION("4.2 remove") @@ -420,8 +421,9 @@ TEST_CASE("JSON patch") // references neither the root of the document, nor a member of // an existing object, nor a member of an existing array. - CHECK_THROWS_AS(doc.patch(patch), std::out_of_range); - CHECK_THROWS_WITH(doc.patch(patch), "key 'baz' not found"); + CHECK_THROWS_AS(doc.patch(patch), json::out_of_range); + CHECK_THROWS_WITH(doc.patch(patch), + "[json.exception.out_of_range.403] key 'baz' not found"); } // A.13. Invalid JSON Patch Document @@ -780,8 +782,9 @@ TEST_CASE("JSON patch") { json j = {{"foo", 1}, {"bar", 2}}; json patch = {{{"op", "remove"}, {"path", "/baz"}}}; - CHECK_THROWS_AS(j.patch(patch), std::out_of_range); - CHECK_THROWS_WITH(j.patch(patch), "key 'baz' not found"); + CHECK_THROWS_AS(j.patch(patch), json::out_of_range); + CHECK_THROWS_WITH(j.patch(patch), + "[json.exception.out_of_range.403] key 'baz' not found"); } SECTION("root element as target location") @@ -835,8 +838,9 @@ TEST_CASE("JSON patch") { json j = {{"foo", 1}, {"bar", 2}}; json patch = {{{"op", "replace"}, {"path", "/baz"}, {"value", 3}}}; - CHECK_THROWS_AS(j.patch(patch), std::out_of_range); - CHECK_THROWS_WITH(j.patch(patch), "key 'baz' not found"); + CHECK_THROWS_AS(j.patch(patch), json::out_of_range); + CHECK_THROWS_WITH(j.patch(patch), + "[json.exception.out_of_range.403] key 'baz' not found"); } } @@ -891,8 +895,9 @@ TEST_CASE("JSON patch") { json j = {{"foo", 1}, {"bar", 2}}; json patch = {{{"op", "move"}, {"path", "/baz"}, {"from", "/baz"}}}; - CHECK_THROWS_AS(j.patch(patch), std::out_of_range); - CHECK_THROWS_WITH(j.patch(patch), "key 'baz' not found"); + CHECK_THROWS_AS(j.patch(patch), json::out_of_range); + CHECK_THROWS_WITH(j.patch(patch), + "[json.exception.out_of_range.403] key 'baz' not found"); } } @@ -947,8 +952,9 @@ TEST_CASE("JSON patch") { json j = {{"foo", 1}, {"bar", 2}}; json patch = {{{"op", "copy"}, {"path", "/fob"}, {"from", "/baz"}}}; - CHECK_THROWS_AS(j.patch(patch), std::out_of_range); - CHECK_THROWS_WITH(j.patch(patch), "key 'baz' not found"); + CHECK_THROWS_AS(j.patch(patch), json::out_of_range); + CHECK_THROWS_WITH(j.patch(patch), + "[json.exception.out_of_range.403] key 'baz' not found"); } } diff --git a/test/src/unit-json_pointer.cpp b/test/src/unit-json_pointer.cpp index db45a9666..c12a56adf 100644 --- a/test/src/unit-json_pointer.cpp +++ b/test/src/unit-json_pointer.cpp @@ -185,8 +185,9 @@ TEST_CASE("JSON pointers") CHECK(j[json::json_pointer("/m~0n")] == j["m~n"]); // unescaped access - CHECK_THROWS_AS(j.at(json::json_pointer("/a/b")), std::out_of_range); - CHECK_THROWS_WITH(j.at(json::json_pointer("/a/b")), "key 'a' not found"); + CHECK_THROWS_AS(j.at(json::json_pointer("/a/b")), json::out_of_range); + CHECK_THROWS_WITH(j.at(json::json_pointer("/a/b")), + "[json.exception.out_of_range.403] key 'a' not found"); // unresolved access const json j_primitive = 1;