🔨 added user-defined exceptions 203-204

parent 9381f6c4
...@@ -2418,7 +2418,7 @@ class basic_json ...@@ -2418,7 +2418,7 @@ class basic_json
@throw invalid_iterator.201 if iterators are not compatible; that is, do @throw invalid_iterator.201 if iterators are not compatible; that is, do
not belong to the same JSON value; example: `"iterators are not not belong to the same JSON value; example: `"iterators are not
compatible"` compatible"`
@throw std::out_of_range if iterators are for a primitive type (number, @throw invalid_iterator.204 if iterators are for a primitive type (number,
boolean, or string) where an out of range error can be detected easily; boolean, or string) where an out of range error can be detected easily;
example: `"iterators out of range"` example: `"iterators out of range"`
@throw std::bad_alloc if allocation for object, array, or string fails @throw std::bad_alloc if allocation for object, array, or string fails
...@@ -2460,7 +2460,7 @@ class basic_json ...@@ -2460,7 +2460,7 @@ class basic_json
{ {
if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end()) if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
{ {
JSON_THROW(std::out_of_range("iterators out of range")); JSON_THROW(invalid_iterator(204, "iterators out of range"));
} }
break; break;
} }
...@@ -4507,9 +4507,9 @@ class basic_json ...@@ -4507,9 +4507,9 @@ class basic_json
@throw std::domain_error if called on a `null` value; example: `"cannot @throw std::domain_error if called on a `null` value; example: `"cannot
use erase() with null"` use erase() with null"`
@throw std::domain_error if called on iterators which does not belong to @throw invalid_iterator.203 if called on iterators which does not belong
the current JSON value; example: `"iterators do not fit current value"` to the current JSON value; example: `"iterators do not fit current value"`
@throw std::out_of_range if called on a primitive type with invalid @throw invalid_iterator.204 if called on a primitive type with invalid
iterators (i.e., if `first != begin()` and `last != end()`); example: iterators (i.e., if `first != begin()` and `last != end()`); example:
`"iterators out of range"` `"iterators out of range"`
...@@ -4540,7 +4540,7 @@ class basic_json ...@@ -4540,7 +4540,7 @@ class basic_json
// make sure iterator fits the current value // make sure iterator fits the current value
if (this != first.m_object or this != last.m_object) if (this != first.m_object or this != last.m_object)
{ {
JSON_THROW(std::domain_error("iterators do not fit current value")); JSON_THROW(invalid_iterator(203, "iterators do not fit current value"));
} }
IteratorType result = end(); IteratorType result = end();
...@@ -4555,7 +4555,7 @@ class basic_json ...@@ -4555,7 +4555,7 @@ class basic_json
{ {
if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end()) if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
{ {
JSON_THROW(std::out_of_range("iterators out of range")); JSON_THROW(invalid_iterator(204, "iterators out of range"));
} }
if (is_string()) if (is_string())
......
...@@ -2418,7 +2418,7 @@ class basic_json ...@@ -2418,7 +2418,7 @@ class basic_json
@throw invalid_iterator.201 if iterators are not compatible; that is, do @throw invalid_iterator.201 if iterators are not compatible; that is, do
not belong to the same JSON value; example: `"iterators are not not belong to the same JSON value; example: `"iterators are not
compatible"` compatible"`
@throw std::out_of_range if iterators are for a primitive type (number, @throw invalid_iterator.204 if iterators are for a primitive type (number,
boolean, or string) where an out of range error can be detected easily; boolean, or string) where an out of range error can be detected easily;
example: `"iterators out of range"` example: `"iterators out of range"`
@throw std::bad_alloc if allocation for object, array, or string fails @throw std::bad_alloc if allocation for object, array, or string fails
...@@ -2460,7 +2460,7 @@ class basic_json ...@@ -2460,7 +2460,7 @@ class basic_json
{ {
if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end()) if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
{ {
JSON_THROW(std::out_of_range("iterators out of range")); JSON_THROW(invalid_iterator(204, "iterators out of range"));
} }
break; break;
} }
...@@ -4507,9 +4507,9 @@ class basic_json ...@@ -4507,9 +4507,9 @@ class basic_json
@throw std::domain_error if called on a `null` value; example: `"cannot @throw std::domain_error if called on a `null` value; example: `"cannot
use erase() with null"` use erase() with null"`
@throw std::domain_error if called on iterators which does not belong to @throw invalid_iterator.203 if called on iterators which does not belong
the current JSON value; example: `"iterators do not fit current value"` to the current JSON value; example: `"iterators do not fit current value"`
@throw std::out_of_range if called on a primitive type with invalid @throw invalid_iterator.204 if called on a primitive type with invalid
iterators (i.e., if `first != begin()` and `last != end()`); example: iterators (i.e., if `first != begin()` and `last != end()`); example:
`"iterators out of range"` `"iterators out of range"`
...@@ -4540,7 +4540,7 @@ class basic_json ...@@ -4540,7 +4540,7 @@ class basic_json
// make sure iterator fits the current value // make sure iterator fits the current value
if (this != first.m_object or this != last.m_object) if (this != first.m_object or this != last.m_object)
{ {
JSON_THROW(std::domain_error("iterators do not fit current value")); JSON_THROW(invalid_iterator(203, "iterators do not fit current value"));
} }
IteratorType result = end(); IteratorType result = end();
...@@ -4555,7 +4555,7 @@ class basic_json ...@@ -4555,7 +4555,7 @@ class basic_json
{ {
if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end()) if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
{ {
JSON_THROW(std::out_of_range("iterators out of range")); JSON_THROW(invalid_iterator(204, "iterators out of range"));
} }
if (is_string()) if (is_string())
......
...@@ -1193,17 +1193,17 @@ TEST_CASE("constructors") ...@@ -1193,17 +1193,17 @@ TEST_CASE("constructors")
{ {
{ {
json j = "foo"; json j = "foo";
CHECK_THROWS_AS(json(j.end(), j.end()), std::out_of_range); CHECK_THROWS_AS(json(j.end(), j.end()), json::invalid_iterator);
CHECK_THROWS_AS(json(j.begin(), j.begin()), std::out_of_range); CHECK_THROWS_AS(json(j.begin(), j.begin()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.end(), j.end()), "iterators out of range"); CHECK_THROWS_WITH(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range");
CHECK_THROWS_WITH(json(j.begin(), j.begin()), "iterators out of range"); CHECK_THROWS_WITH(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range");
} }
{ {
json j = "bar"; json j = "bar";
CHECK_THROWS_AS(json(j.cend(), j.cend()), std::out_of_range); CHECK_THROWS_AS(json(j.cend(), j.cend()), json::invalid_iterator);
CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), std::out_of_range); CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.cend(), j.cend()), "iterators out of range"); CHECK_THROWS_WITH(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range");
CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "iterators out of range"); CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range");
} }
} }
...@@ -1211,17 +1211,17 @@ TEST_CASE("constructors") ...@@ -1211,17 +1211,17 @@ TEST_CASE("constructors")
{ {
{ {
json j = false; json j = false;
CHECK_THROWS_AS(json(j.end(), j.end()), std::out_of_range); CHECK_THROWS_AS(json(j.end(), j.end()), json::invalid_iterator);
CHECK_THROWS_AS(json(j.begin(), j.begin()), std::out_of_range); CHECK_THROWS_AS(json(j.begin(), j.begin()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.end(), j.end()), "iterators out of range"); CHECK_THROWS_WITH(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range");
CHECK_THROWS_WITH(json(j.begin(), j.begin()), "iterators out of range"); CHECK_THROWS_WITH(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range");
} }
{ {
json j = true; json j = true;
CHECK_THROWS_AS(json(j.cend(), j.cend()), std::out_of_range); CHECK_THROWS_AS(json(j.cend(), j.cend()), json::invalid_iterator);
CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), std::out_of_range); CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.cend(), j.cend()), "iterators out of range"); CHECK_THROWS_WITH(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range");
CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "iterators out of range"); CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range");
} }
} }
...@@ -1229,17 +1229,17 @@ TEST_CASE("constructors") ...@@ -1229,17 +1229,17 @@ TEST_CASE("constructors")
{ {
{ {
json j = 17; json j = 17;
CHECK_THROWS_AS(json(j.end(), j.end()), std::out_of_range); CHECK_THROWS_AS(json(j.end(), j.end()), json::invalid_iterator);
CHECK_THROWS_AS(json(j.begin(), j.begin()), std::out_of_range); CHECK_THROWS_AS(json(j.begin(), j.begin()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.end(), j.end()), "iterators out of range"); CHECK_THROWS_WITH(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range");
CHECK_THROWS_WITH(json(j.begin(), j.begin()), "iterators out of range"); CHECK_THROWS_WITH(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range");
} }
{ {
json j = 17; json j = 17;
CHECK_THROWS_AS(json(j.cend(), j.cend()), std::out_of_range); CHECK_THROWS_AS(json(j.cend(), j.cend()), json::invalid_iterator);
CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), std::out_of_range); CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.cend(), j.cend()), "iterators out of range"); CHECK_THROWS_WITH(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range");
CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "iterators out of range"); CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range");
} }
} }
...@@ -1247,17 +1247,17 @@ TEST_CASE("constructors") ...@@ -1247,17 +1247,17 @@ TEST_CASE("constructors")
{ {
{ {
json j = 17u; json j = 17u;
CHECK_THROWS_AS(json(j.end(), j.end()), std::out_of_range); CHECK_THROWS_AS(json(j.end(), j.end()), json::invalid_iterator);
CHECK_THROWS_AS(json(j.begin(), j.begin()), std::out_of_range); CHECK_THROWS_AS(json(j.begin(), j.begin()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.end(), j.end()), "iterators out of range"); CHECK_THROWS_WITH(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range");
CHECK_THROWS_WITH(json(j.begin(), j.begin()), "iterators out of range"); CHECK_THROWS_WITH(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range");
} }
{ {
json j = 17u; json j = 17u;
CHECK_THROWS_AS(json(j.cend(), j.cend()), std::out_of_range); CHECK_THROWS_AS(json(j.cend(), j.cend()), json::invalid_iterator);
CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), std::out_of_range); CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.cend(), j.cend()), "iterators out of range"); CHECK_THROWS_WITH(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range");
CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "iterators out of range"); CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range");
} }
} }
...@@ -1265,17 +1265,17 @@ TEST_CASE("constructors") ...@@ -1265,17 +1265,17 @@ TEST_CASE("constructors")
{ {
{ {
json j = 23.42; json j = 23.42;
CHECK_THROWS_AS(json(j.end(), j.end()), std::out_of_range); CHECK_THROWS_AS(json(j.end(), j.end()), json::invalid_iterator);
CHECK_THROWS_AS(json(j.begin(), j.begin()), std::out_of_range); CHECK_THROWS_AS(json(j.begin(), j.begin()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.end(), j.end()), "iterators out of range"); CHECK_THROWS_WITH(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range");
CHECK_THROWS_WITH(json(j.begin(), j.begin()), "iterators out of range"); CHECK_THROWS_WITH(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range");
} }
{ {
json j = 23.42; json j = 23.42;
CHECK_THROWS_AS(json(j.cend(), j.cend()), std::out_of_range); CHECK_THROWS_AS(json(j.cend(), j.cend()), json::invalid_iterator);
CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), std::out_of_range); CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.cend(), j.cend()), "iterators out of range"); CHECK_THROWS_WITH(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range");
CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "iterators out of range"); CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range");
} }
} }
} }
......
This diff is collapsed.
...@@ -686,33 +686,33 @@ TEST_CASE("element access 2") ...@@ -686,33 +686,33 @@ TEST_CASE("element access 2")
json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}}; json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}}; json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
CHECK_THROWS_AS(jobject.erase(jobject2.begin()), json::invalid_iterator); CHECK_THROWS_AS(jobject.erase(jobject2.begin()), json::invalid_iterator);
CHECK_THROWS_AS(jobject.erase(jobject.begin(), jobject2.end()), std::domain_error); CHECK_THROWS_AS(jobject.erase(jobject.begin(), jobject2.end()), json::invalid_iterator);
CHECK_THROWS_AS(jobject.erase(jobject2.begin(), jobject.end()), std::domain_error); CHECK_THROWS_AS(jobject.erase(jobject2.begin(), jobject.end()), json::invalid_iterator);
CHECK_THROWS_AS(jobject.erase(jobject2.begin(), jobject2.end()), std::domain_error); CHECK_THROWS_AS(jobject.erase(jobject2.begin(), jobject2.end()), json::invalid_iterator);
CHECK_THROWS_WITH(jobject.erase(jobject2.begin()), CHECK_THROWS_WITH(jobject.erase(jobject2.begin()),
"[json.exception.invalid_iterator.202] iterator does not fit current value"); "[json.exception.invalid_iterator.202] iterator does not fit current value");
CHECK_THROWS_WITH(jobject.erase(jobject.begin(), jobject2.end()), CHECK_THROWS_WITH(jobject.erase(jobject.begin(), jobject2.end()),
"iterators do not fit current value"); "[json.exception.invalid_iterator.203] iterators do not fit current value");
CHECK_THROWS_WITH(jobject.erase(jobject2.begin(), jobject.end()), CHECK_THROWS_WITH(jobject.erase(jobject2.begin(), jobject.end()),
"iterators do not fit current value"); "[json.exception.invalid_iterator.203] iterators do not fit current value");
CHECK_THROWS_WITH(jobject.erase(jobject2.begin(), jobject2.end()), CHECK_THROWS_WITH(jobject.erase(jobject2.begin(), jobject2.end()),
"iterators do not fit current value"); "[json.exception.invalid_iterator.203] iterators do not fit current value");
} }
{ {
json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}}; json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}}; json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
CHECK_THROWS_AS(jobject.erase(jobject2.cbegin()), json::invalid_iterator); CHECK_THROWS_AS(jobject.erase(jobject2.cbegin()), json::invalid_iterator);
CHECK_THROWS_AS(jobject.erase(jobject.cbegin(), jobject2.cend()), std::domain_error); CHECK_THROWS_AS(jobject.erase(jobject.cbegin(), jobject2.cend()), json::invalid_iterator);
CHECK_THROWS_AS(jobject.erase(jobject2.cbegin(), jobject.cend()), std::domain_error); CHECK_THROWS_AS(jobject.erase(jobject2.cbegin(), jobject.cend()), json::invalid_iterator);
CHECK_THROWS_AS(jobject.erase(jobject2.cbegin(), jobject2.cend()), std::domain_error); CHECK_THROWS_AS(jobject.erase(jobject2.cbegin(), jobject2.cend()), json::invalid_iterator);
CHECK_THROWS_WITH(jobject.erase(jobject2.cbegin()), CHECK_THROWS_WITH(jobject.erase(jobject2.cbegin()),
"[json.exception.invalid_iterator.202] iterator does not fit current value"); "[json.exception.invalid_iterator.202] iterator does not fit current value");
CHECK_THROWS_WITH(jobject.erase(jobject.cbegin(), jobject2.cend()), CHECK_THROWS_WITH(jobject.erase(jobject.cbegin(), jobject2.cend()),
"iterators do not fit current value"); "[json.exception.invalid_iterator.203] iterators do not fit current value");
CHECK_THROWS_WITH(jobject.erase(jobject2.cbegin(), jobject.cend()), CHECK_THROWS_WITH(jobject.erase(jobject2.cbegin(), jobject.cend()),
"iterators do not fit current value"); "[json.exception.invalid_iterator.203] iterators do not fit current value");
CHECK_THROWS_WITH(jobject.erase(jobject2.cbegin(), jobject2.cend()), CHECK_THROWS_WITH(jobject.erase(jobject2.cbegin(), jobject2.cend()),
"iterators do not fit current value"); "[json.exception.invalid_iterator.203] iterators do not fit current value");
} }
} }
} }
......
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