diff --git a/src/json.hpp b/src/json.hpp index 41a85eaa..5511dcd5 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -283,6 +283,7 @@ json.exception.out_of_range.402 | array index '-' (3) is out of range | The spec json.exception.out_of_range.403 | key 'foo' not found | The provided key was not found in the JSON object. json.exception.out_of_range.404 | unresolved reference token 'foo' | A reference token in a JSON Pointer could not be resolved. json.exception.out_of_range.405 | JSON pointer has no parent | The JSON Patch operations 'remove' and 'add' can not be applied to the root element of the JSON value. +json.exception.out_of_range.406 | number overflow parsing '10E1000' | A parsed number could not be stored as without changing it to NaN or INF. @since version 3.0.0 */ @@ -11717,7 +11718,7 @@ basic_json_parser_74: // throw in case of infinity or NAN if (not std::isfinite(result.m_value.number_float)) { - JSON_THROW(std::out_of_range("number overflow: " + get_token_string())); + JSON_THROW(out_of_range(406, "number overflow parsing '" + get_token_string() + "'")); } return true; diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 711dd688..f1173688 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -283,6 +283,7 @@ json.exception.out_of_range.402 | array index '-' (3) is out of range | The spec json.exception.out_of_range.403 | key 'foo' not found | The provided key was not found in the JSON object. json.exception.out_of_range.404 | unresolved reference token 'foo' | A reference token in a JSON Pointer could not be resolved. json.exception.out_of_range.405 | JSON pointer has no parent | The JSON Patch operations 'remove' and 'add' can not be applied to the root element of the JSON value. +json.exception.out_of_range.406 | number overflow parsing '10E1000' | A parsed number could not be stored as without changing it to NaN or INF. @since version 3.0.0 */ @@ -10750,7 +10751,7 @@ class basic_json // throw in case of infinity or NAN if (not std::isfinite(result.m_value.number_float)) { - JSON_THROW(std::out_of_range("number overflow: " + get_token_string())); + JSON_THROW(out_of_range(406, "number overflow parsing '" + get_token_string() + "'")); } return true; diff --git a/test/src/unit-class_parser.cpp b/test/src/unit-class_parser.cpp index c9240c9f..61aa1c37 100644 --- a/test/src/unit-class_parser.cpp +++ b/test/src/unit-class_parser.cpp @@ -277,8 +277,9 @@ TEST_CASE("parser class") SECTION("overflow") { // overflows during parsing yield an exception - CHECK_THROWS_AS(json::parser("1.18973e+4932").parse() == json(), std::out_of_range); - CHECK_THROWS_WITH(json::parser("1.18973e+4932").parse() == json(), "number overflow: 1.18973e+4932"); + CHECK_THROWS_AS(json::parser("1.18973e+4932").parse() == json(), json::out_of_range); + CHECK_THROWS_WITH(json::parser("1.18973e+4932").parse() == json(), + "[json.exception.out_of_range.406] number overflow parsing '1.18973e+4932'"); } SECTION("invalid numbers") diff --git a/test/src/unit-regression.cpp b/test/src/unit-regression.cpp index a8287aeb..33f7a9ef 100644 --- a/test/src/unit-regression.cpp +++ b/test/src/unit-regression.cpp @@ -590,8 +590,9 @@ TEST_CASE("regression tests") SECTION("issue #329 - serialized value not always can be parsed") { - CHECK_THROWS_AS(json::parse("22e2222"), std::out_of_range); - CHECK_THROWS_WITH(json::parse("22e2222"), "number overflow: 22e2222"); + CHECK_THROWS_AS(json::parse("22e2222"), json::out_of_range); + CHECK_THROWS_WITH(json::parse("22e2222"), + "[json.exception.out_of_range.406] number overflow parsing '22e2222'"); } SECTION("issue #366 - json::parse on failed stream gets stuck") diff --git a/test/src/unit-testsuites.cpp b/test/src/unit-testsuites.cpp index 71b45b91..8d6a8162 100644 --- a/test/src/unit-testsuites.cpp +++ b/test/src/unit-testsuites.cpp @@ -797,7 +797,7 @@ TEST_CASE("nst's JSONTestSuite") CAPTURE(filename); std::ifstream f(filename); json j; - CHECK_THROWS_AS(j << f, std::out_of_range); + CHECK_THROWS_AS(j << f, json::out_of_range); } }