🔨 added user-defined exceptions 313-315

parent 144cf6a4
...@@ -12059,7 +12059,7 @@ basic_json_parser_74: ...@@ -12059,7 +12059,7 @@ basic_json_parser_74:
*/ */
default: default:
{ {
JSON_THROW(std::domain_error("invalid value to unflatten")); JSON_THROW(type_error(313, "invalid value to unflatten"));
} }
} }
} }
...@@ -12496,7 +12496,7 @@ basic_json_parser_74: ...@@ -12496,7 +12496,7 @@ basic_json_parser_74:
{ {
if (not value.is_object()) if (not value.is_object())
{ {
JSON_THROW(std::domain_error("only objects can be unflattened")); JSON_THROW(type_error(314, "only objects can be unflattened"));
} }
basic_json result; basic_json result;
...@@ -12506,7 +12506,7 @@ basic_json_parser_74: ...@@ -12506,7 +12506,7 @@ basic_json_parser_74:
{ {
if (not element.second.is_primitive()) if (not element.second.is_primitive())
{ {
JSON_THROW(std::domain_error("values in object must be primitive")); JSON_THROW(type_error(315, "values in object must be primitive"));
} }
// assign value to reference pointed to by JSON pointer; Note // assign value to reference pointed to by JSON pointer; Note
......
...@@ -11092,7 +11092,7 @@ class basic_json ...@@ -11092,7 +11092,7 @@ class basic_json
*/ */
default: default:
{ {
JSON_THROW(std::domain_error("invalid value to unflatten")); JSON_THROW(type_error(313, "invalid value to unflatten"));
} }
} }
} }
...@@ -11529,7 +11529,7 @@ class basic_json ...@@ -11529,7 +11529,7 @@ class basic_json
{ {
if (not value.is_object()) if (not value.is_object())
{ {
JSON_THROW(std::domain_error("only objects can be unflattened")); JSON_THROW(type_error(314, "only objects can be unflattened"));
} }
basic_json result; basic_json result;
...@@ -11539,7 +11539,7 @@ class basic_json ...@@ -11539,7 +11539,7 @@ class basic_json
{ {
if (not element.second.is_primitive()) if (not element.second.is_primitive())
{ {
JSON_THROW(std::domain_error("values in object must be primitive")); JSON_THROW(type_error(315, "values in object must be primitive"));
} }
// assign value to reference pointed to by JSON pointer; Note // assign value to reference pointed to by JSON pointer; Note
......
...@@ -358,17 +358,20 @@ TEST_CASE("JSON pointers") ...@@ -358,17 +358,20 @@ TEST_CASE("JSON pointers")
CHECK(j_flatten.unflatten() == j); CHECK(j_flatten.unflatten() == j);
// error for nonobjects // error for nonobjects
CHECK_THROWS_AS(json(1).unflatten(), std::domain_error); CHECK_THROWS_AS(json(1).unflatten(), json::type_error);
CHECK_THROWS_WITH(json(1).unflatten(), "only objects can be unflattened"); CHECK_THROWS_WITH(json(1).unflatten(),
"[json.exception.type_error.314] only objects can be unflattened");
// error for nonprimitve values // error for nonprimitve values
CHECK_THROWS_AS(json({{"/1", {1, 2, 3}}}).unflatten(), std::domain_error); CHECK_THROWS_AS(json({{"/1", {1, 2, 3}}}).unflatten(), json::type_error);
CHECK_THROWS_WITH(json({{"/1", {1, 2, 3}}}).unflatten(), "values in object must be primitive"); CHECK_THROWS_WITH(json({{"/1", {1, 2, 3}}}).unflatten(),
"[json.exception.type_error.315] values in object must be primitive");
// error for conflicting values // error for conflicting values
json j_error = {{"", 42}, {"/foo", 17}}; json j_error = {{"", 42}, {"/foo", 17}};
CHECK_THROWS_AS(j_error.unflatten(), std::domain_error); CHECK_THROWS_AS(j_error.unflatten(), json::type_error);
CHECK_THROWS_WITH(j_error.unflatten(), "invalid value to unflatten"); CHECK_THROWS_WITH(j_error.unflatten(),
"[json.exception.type_error.313] invalid value to unflatten");
// explicit roundtrip check // explicit roundtrip check
CHECK(j.flatten().unflatten() == j); CHECK(j.flatten().unflatten() == j);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment