added user-defined exceptions 404-405
This commit is contained in:
parent
30331fa21f
commit
38c2e20ce8
4 changed files with 35 additions and 28 deletions
14
src/json.hpp
14
src/json.hpp
|
@ -11974,7 +11974,7 @@ basic_json_parser_74:
|
||||||
{
|
{
|
||||||
if (is_root())
|
if (is_root())
|
||||||
{
|
{
|
||||||
JSON_THROW(std::domain_error("JSON pointer has no parent"));
|
JSON_THROW(out_of_range(405, "JSON pointer has no parent"));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto last = reference_tokens.back();
|
auto last = reference_tokens.back();
|
||||||
|
@ -11992,7 +11992,7 @@ basic_json_parser_74:
|
||||||
{
|
{
|
||||||
if (is_root())
|
if (is_root())
|
||||||
{
|
{
|
||||||
JSON_THROW(std::domain_error("JSON pointer has no parent"));
|
JSON_THROW(out_of_range(405, "JSON pointer has no parent"));
|
||||||
}
|
}
|
||||||
|
|
||||||
json_pointer result = *this;
|
json_pointer result = *this;
|
||||||
|
@ -12083,7 +12083,7 @@ basic_json_parser_74:
|
||||||
|
|
||||||
@complexity Linear in the length of the JSON pointer.
|
@complexity Linear in the length of the JSON pointer.
|
||||||
|
|
||||||
@throw std::out_of_range if the JSON pointer can not be resolved
|
@throw out_of_range.404 if the JSON pointer can not be resolved
|
||||||
@throw parse_error.106 if an array index begins with '0'
|
@throw parse_error.106 if an array index begins with '0'
|
||||||
@throw std::invalid_argument if an array index was not a number
|
@throw std::invalid_argument if an array index was not a number
|
||||||
*/
|
*/
|
||||||
|
@ -12153,7 +12153,7 @@ basic_json_parser_74:
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
JSON_THROW(std::out_of_range("unresolved reference token '" + reference_token + "'"));
|
JSON_THROW(out_of_range(404, "unresolved reference token '" + reference_token + "'"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12204,7 +12204,7 @@ basic_json_parser_74:
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
JSON_THROW(std::out_of_range("unresolved reference token '" + reference_token + "'"));
|
JSON_THROW(out_of_range(404, "unresolved reference token '" + reference_token + "'"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12263,7 +12263,7 @@ basic_json_parser_74:
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
JSON_THROW(std::out_of_range("unresolved reference token '" + reference_token + "'"));
|
JSON_THROW(out_of_range(404, "unresolved reference token '" + reference_token + "'"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12314,7 +12314,7 @@ basic_json_parser_74:
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
JSON_THROW(std::out_of_range("unresolved reference token '" + reference_token + "'"));
|
JSON_THROW(out_of_range(404, "unresolved reference token '" + reference_token + "'"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11007,7 +11007,7 @@ class basic_json
|
||||||
{
|
{
|
||||||
if (is_root())
|
if (is_root())
|
||||||
{
|
{
|
||||||
JSON_THROW(std::domain_error("JSON pointer has no parent"));
|
JSON_THROW(out_of_range(405, "JSON pointer has no parent"));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto last = reference_tokens.back();
|
auto last = reference_tokens.back();
|
||||||
|
@ -11025,7 +11025,7 @@ class basic_json
|
||||||
{
|
{
|
||||||
if (is_root())
|
if (is_root())
|
||||||
{
|
{
|
||||||
JSON_THROW(std::domain_error("JSON pointer has no parent"));
|
JSON_THROW(out_of_range(405, "JSON pointer has no parent"));
|
||||||
}
|
}
|
||||||
|
|
||||||
json_pointer result = *this;
|
json_pointer result = *this;
|
||||||
|
@ -11116,7 +11116,7 @@ class basic_json
|
||||||
|
|
||||||
@complexity Linear in the length of the JSON pointer.
|
@complexity Linear in the length of the JSON pointer.
|
||||||
|
|
||||||
@throw std::out_of_range if the JSON pointer can not be resolved
|
@throw out_of_range.404 if the JSON pointer can not be resolved
|
||||||
@throw parse_error.106 if an array index begins with '0'
|
@throw parse_error.106 if an array index begins with '0'
|
||||||
@throw std::invalid_argument if an array index was not a number
|
@throw std::invalid_argument if an array index was not a number
|
||||||
*/
|
*/
|
||||||
|
@ -11186,7 +11186,7 @@ class basic_json
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
JSON_THROW(std::out_of_range("unresolved reference token '" + reference_token + "'"));
|
JSON_THROW(out_of_range(404, "unresolved reference token '" + reference_token + "'"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11237,7 +11237,7 @@ class basic_json
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
JSON_THROW(std::out_of_range("unresolved reference token '" + reference_token + "'"));
|
JSON_THROW(out_of_range(404, "unresolved reference token '" + reference_token + "'"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11296,7 +11296,7 @@ class basic_json
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
JSON_THROW(std::out_of_range("unresolved reference token '" + reference_token + "'"));
|
JSON_THROW(out_of_range(404, "unresolved reference token '" + reference_token + "'"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11347,7 +11347,7 @@ class basic_json
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
JSON_THROW(std::out_of_range("unresolved reference token '" + reference_token + "'"));
|
JSON_THROW(out_of_range(404, "unresolved reference token '" + reference_token + "'"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -791,8 +791,9 @@ TEST_CASE("JSON patch")
|
||||||
{
|
{
|
||||||
json j = "string";
|
json j = "string";
|
||||||
json patch = {{{"op", "remove"}, {"path", ""}}};
|
json patch = {{{"op", "remove"}, {"path", ""}}};
|
||||||
CHECK_THROWS_AS(j.patch(patch), std::domain_error);
|
CHECK_THROWS_AS(j.patch(patch), json::out_of_range);
|
||||||
CHECK_THROWS_WITH(j.patch(patch), "JSON pointer has no parent");
|
CHECK_THROWS_WITH(j.patch(patch),
|
||||||
|
"[json.exception.out_of_range.405] JSON pointer has no parent");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,10 +49,12 @@ TEST_CASE("JSON pointers")
|
||||||
"[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'");
|
"[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'");
|
||||||
|
|
||||||
json::json_pointer p;
|
json::json_pointer p;
|
||||||
CHECK_THROWS_AS(p.top(), std::domain_error);
|
CHECK_THROWS_AS(p.top(), json::out_of_range);
|
||||||
CHECK_THROWS_WITH(p.top(), "JSON pointer has no parent");
|
CHECK_THROWS_WITH(p.top(),
|
||||||
CHECK_THROWS_AS(p.pop_back(), std::domain_error);
|
"[json.exception.out_of_range.405] JSON pointer has no parent");
|
||||||
CHECK_THROWS_WITH(p.pop_back(), "JSON pointer has no parent");
|
CHECK_THROWS_AS(p.pop_back(), json::out_of_range);
|
||||||
|
CHECK_THROWS_WITH(p.pop_back(),
|
||||||
|
"[json.exception.out_of_range.405] JSON pointer has no parent");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("examples from RFC 6901")
|
SECTION("examples from RFC 6901")
|
||||||
|
@ -124,10 +126,12 @@ TEST_CASE("JSON pointers")
|
||||||
|
|
||||||
// unresolved access
|
// unresolved access
|
||||||
json j_primitive = 1;
|
json j_primitive = 1;
|
||||||
CHECK_THROWS_AS(j_primitive["/foo"_json_pointer], std::out_of_range);
|
CHECK_THROWS_AS(j_primitive["/foo"_json_pointer], json::out_of_range);
|
||||||
CHECK_THROWS_WITH(j_primitive["/foo"_json_pointer], "unresolved reference token 'foo'");
|
CHECK_THROWS_WITH(j_primitive["/foo"_json_pointer],
|
||||||
CHECK_THROWS_AS(j_primitive.at("/foo"_json_pointer), std::out_of_range);
|
"[json.exception.out_of_range.404] unresolved reference token 'foo'");
|
||||||
CHECK_THROWS_WITH(j_primitive.at("/foo"_json_pointer), "unresolved reference token 'foo'");
|
CHECK_THROWS_AS(j_primitive.at("/foo"_json_pointer), json::out_of_range);
|
||||||
|
CHECK_THROWS_WITH(j_primitive.at("/foo"_json_pointer),
|
||||||
|
"[json.exception.out_of_range.404] unresolved reference token 'foo'");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("const access")
|
SECTION("const access")
|
||||||
|
@ -191,10 +195,12 @@ TEST_CASE("JSON pointers")
|
||||||
|
|
||||||
// unresolved access
|
// unresolved access
|
||||||
const json j_primitive = 1;
|
const json j_primitive = 1;
|
||||||
CHECK_THROWS_AS(j_primitive["/foo"_json_pointer], std::out_of_range);
|
CHECK_THROWS_AS(j_primitive["/foo"_json_pointer], json::out_of_range);
|
||||||
CHECK_THROWS_WITH(j_primitive["/foo"_json_pointer], "unresolved reference token 'foo'");
|
CHECK_THROWS_WITH(j_primitive["/foo"_json_pointer],
|
||||||
CHECK_THROWS_AS(j_primitive.at("/foo"_json_pointer), std::out_of_range);
|
"[json.exception.out_of_range.404] unresolved reference token 'foo'");
|
||||||
CHECK_THROWS_WITH(j_primitive.at("/foo"_json_pointer), "unresolved reference token 'foo'");
|
CHECK_THROWS_AS(j_primitive.at("/foo"_json_pointer), json::out_of_range);
|
||||||
|
CHECK_THROWS_WITH(j_primitive.at("/foo"_json_pointer),
|
||||||
|
"[json.exception.out_of_range.404] unresolved reference token 'foo'");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("user-defined string literal")
|
SECTION("user-defined string literal")
|
||||||
|
|
Loading…
Reference in a new issue