🔨 added user-defined exceptions 307

parent bb740c43
......@@ -4397,8 +4397,8 @@ class basic_json
@post Invalidates iterators and references at or after the point of the
erase, including the `end()` iterator.
@throw std::domain_error if called on a `null` value; example: `"cannot
use erase() with null"`
@throw type_error.307 if called on a `null` value; example: `"cannot use
erase() with null"`
@throw invalid_iterator.202 if called on an iterator which does not belong
to the current JSON value; example: `"iterator does not fit current
value"`
......@@ -4478,7 +4478,7 @@ class basic_json
default:
{
JSON_THROW(std::domain_error("cannot use erase() with " + type_name()));
JSON_THROW(type_error(307, "cannot use erase() with " + type_name()));
}
}
......@@ -4505,8 +4505,8 @@ class basic_json
@post Invalidates iterators and references at or after the point of the
erase, including the `end()` iterator.
@throw std::domain_error if called on a `null` value; example: `"cannot
use erase() with null"`
@throw type_error.307 if called on a `null` value; example: `"cannot use
erase() with null"`
@throw invalid_iterator.203 if called on iterators which does not belong
to the current JSON value; example: `"iterators do not fit current value"`
@throw invalid_iterator.204 if called on a primitive type with invalid
......@@ -4587,7 +4587,7 @@ class basic_json
default:
{
JSON_THROW(std::domain_error("cannot use erase() with " + type_name()));
JSON_THROW(type_error(307, "cannot use erase() with " + type_name()));
}
}
......@@ -4608,7 +4608,7 @@ class basic_json
@post References and iterators to the erased elements are invalidated.
Other references and iterators are not affected.
@throw std::domain_error when called on a type other than JSON object;
@throw type_error.307 when called on a type other than JSON object;
example: `"cannot use erase() with null"`
@complexity `log(size()) + count(key)`
......@@ -4631,7 +4631,7 @@ class basic_json
return m_value.object->erase(key);
}
JSON_THROW(std::domain_error("cannot use erase() with " + type_name()));
JSON_THROW(type_error(307, "cannot use erase() with " + type_name()));
}
/*!
......@@ -4641,7 +4641,7 @@ class basic_json
@param[in] idx index of the element to remove
@throw std::domain_error when called on a type other than JSON array;
@throw type_error.307 when called on a type other than JSON object;
example: `"cannot use erase() with null"`
@throw std::out_of_range when `idx >= size()`; example: `"array index 17
is out of range"`
......@@ -4672,7 +4672,7 @@ class basic_json
}
else
{
JSON_THROW(std::domain_error("cannot use erase() with " + type_name()));
JSON_THROW(type_error(307, "cannot use erase() with " + type_name()));
}
}
......
......@@ -4397,8 +4397,8 @@ class basic_json
@post Invalidates iterators and references at or after the point of the
erase, including the `end()` iterator.
@throw std::domain_error if called on a `null` value; example: `"cannot
use erase() with null"`
@throw type_error.307 if called on a `null` value; example: `"cannot use
erase() with null"`
@throw invalid_iterator.202 if called on an iterator which does not belong
to the current JSON value; example: `"iterator does not fit current
value"`
......@@ -4478,7 +4478,7 @@ class basic_json
default:
{
JSON_THROW(std::domain_error("cannot use erase() with " + type_name()));
JSON_THROW(type_error(307, "cannot use erase() with " + type_name()));
}
}
......@@ -4505,8 +4505,8 @@ class basic_json
@post Invalidates iterators and references at or after the point of the
erase, including the `end()` iterator.
@throw std::domain_error if called on a `null` value; example: `"cannot
use erase() with null"`
@throw type_error.307 if called on a `null` value; example: `"cannot use
erase() with null"`
@throw invalid_iterator.203 if called on iterators which does not belong
to the current JSON value; example: `"iterators do not fit current value"`
@throw invalid_iterator.204 if called on a primitive type with invalid
......@@ -4587,7 +4587,7 @@ class basic_json
default:
{
JSON_THROW(std::domain_error("cannot use erase() with " + type_name()));
JSON_THROW(type_error(307, "cannot use erase() with " + type_name()));
}
}
......@@ -4608,7 +4608,7 @@ class basic_json
@post References and iterators to the erased elements are invalidated.
Other references and iterators are not affected.
@throw std::domain_error when called on a type other than JSON object;
@throw type_error.307 when called on a type other than JSON object;
example: `"cannot use erase() with null"`
@complexity `log(size()) + count(key)`
......@@ -4631,7 +4631,7 @@ class basic_json
return m_value.object->erase(key);
}
JSON_THROW(std::domain_error("cannot use erase() with " + type_name()));
JSON_THROW(type_error(307, "cannot use erase() with " + type_name()));
}
/*!
......@@ -4641,7 +4641,7 @@ class basic_json
@param[in] idx index of the element to remove
@throw std::domain_error when called on a type other than JSON array;
@throw type_error.307 when called on a type other than JSON object;
example: `"cannot use erase() with null"`
@throw std::out_of_range when `idx >= size()`; example: `"array index 17
is out of range"`
......@@ -4672,7 +4672,7 @@ class basic_json
}
else
{
JSON_THROW(std::domain_error("cannot use erase() with " + type_name()));
JSON_THROW(type_error(307, "cannot use erase() with " + type_name()));
}
}
......
......@@ -757,43 +757,49 @@ TEST_CASE("element access 2")
SECTION("null")
{
json j_nonobject(json::value_t::null);
CHECK_THROWS_AS(j_nonobject.erase("foo"), std::domain_error);
CHECK_THROWS_WITH(j_nonobject.erase("foo"), "cannot use erase() with null");
CHECK_THROWS_AS(j_nonobject.erase("foo"), json::type_error);
CHECK_THROWS_WITH(j_nonobject.erase("foo"),
"[json.exception.type_error.307] cannot use erase() with null");
}
SECTION("boolean")
{
json j_nonobject(json::value_t::boolean);
CHECK_THROWS_AS(j_nonobject.erase("foo"), std::domain_error);
CHECK_THROWS_WITH(j_nonobject.erase("foo"), "cannot use erase() with boolean");
CHECK_THROWS_AS(j_nonobject.erase("foo"), json::type_error);
CHECK_THROWS_WITH(j_nonobject.erase("foo"),
"[json.exception.type_error.307] cannot use erase() with boolean");
}
SECTION("string")
{
json j_nonobject(json::value_t::string);
CHECK_THROWS_AS(j_nonobject.erase("foo"), std::domain_error);
CHECK_THROWS_WITH(j_nonobject.erase("foo"), "cannot use erase() with string");
CHECK_THROWS_AS(j_nonobject.erase("foo"), json::type_error);
CHECK_THROWS_WITH(j_nonobject.erase("foo"),
"[json.exception.type_error.307] cannot use erase() with string");
}
SECTION("array")
{
json j_nonobject(json::value_t::array);
CHECK_THROWS_AS(j_nonobject.erase("foo"), std::domain_error);
CHECK_THROWS_WITH(j_nonobject.erase("foo"), "cannot use erase() with array");
CHECK_THROWS_AS(j_nonobject.erase("foo"), json::type_error);
CHECK_THROWS_WITH(j_nonobject.erase("foo"),
"[json.exception.type_error.307] cannot use erase() with array");
}
SECTION("number (integer)")
{
json j_nonobject(json::value_t::number_integer);
CHECK_THROWS_AS(j_nonobject.erase("foo"), std::domain_error);
CHECK_THROWS_WITH(j_nonobject.erase("foo"), "cannot use erase() with number");
CHECK_THROWS_AS(j_nonobject.erase("foo"), json::type_error);
CHECK_THROWS_WITH(j_nonobject.erase("foo"),
"[json.exception.type_error.307] cannot use erase() with number");
}
SECTION("number (floating-point)")
{
json j_nonobject(json::value_t::number_float);
CHECK_THROWS_AS(j_nonobject.erase("foo"), std::domain_error);
CHECK_THROWS_WITH(j_nonobject.erase("foo"), "cannot use erase() with number");
CHECK_THROWS_AS(j_nonobject.erase("foo"), json::type_error);
CHECK_THROWS_WITH(j_nonobject.erase("foo"),
"[json.exception.type_error.307] cannot use erase() with number");
}
}
}
......
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