🔨 added user-defined exceptions 309
This commit is contained in:
parent
70b2c3f45e
commit
5cca44c161
3 changed files with 32 additions and 32 deletions
22
src/json.hpp
22
src/json.hpp
|
@ -5655,7 +5655,7 @@ class basic_json
|
||||||
@param[in] val element to insert
|
@param[in] val element to insert
|
||||||
@return iterator pointing to the inserted @a val.
|
@return iterator pointing to the inserted @a val.
|
||||||
|
|
||||||
@throw std::domain_error if called on JSON values other than arrays;
|
@throw type_error.309 if called on JSON values other than arrays;
|
||||||
example: `"cannot use insert() with string"`
|
example: `"cannot use insert() with string"`
|
||||||
@throw invalid_iterator.202 if @a pos is not an iterator of *this;
|
@throw invalid_iterator.202 if @a pos is not an iterator of *this;
|
||||||
example: `"iterator does not fit current value"`
|
example: `"iterator does not fit current value"`
|
||||||
|
@ -5684,7 +5684,7 @@ class basic_json
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON_THROW(std::domain_error("cannot use insert() with " + type_name()));
|
JSON_THROW(type_error(309, "cannot use insert() with " + type_name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -5708,8 +5708,8 @@ class basic_json
|
||||||
@return iterator pointing to the first element inserted, or @a pos if
|
@return iterator pointing to the first element inserted, or @a pos if
|
||||||
`cnt==0`
|
`cnt==0`
|
||||||
|
|
||||||
@throw std::domain_error if called on JSON values other than arrays;
|
@throw type_error.309 if called on JSON values other than arrays; example:
|
||||||
example: `"cannot use insert() with string"`
|
`"cannot use insert() with string"`
|
||||||
@throw invalid_iterator.202 if @a pos is not an iterator of *this;
|
@throw invalid_iterator.202 if @a pos is not an iterator of *this;
|
||||||
example: `"iterator does not fit current value"`
|
example: `"iterator does not fit current value"`
|
||||||
|
|
||||||
|
@ -5737,7 +5737,7 @@ class basic_json
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON_THROW(std::domain_error("cannot use insert() with " + type_name()));
|
JSON_THROW(type_error(309, "cannot use insert() with " + type_name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -5750,8 +5750,8 @@ class basic_json
|
||||||
@param[in] first begin of the range of elements to insert
|
@param[in] first begin of the range of elements to insert
|
||||||
@param[in] last end of the range of elements to insert
|
@param[in] last end of the range of elements to insert
|
||||||
|
|
||||||
@throw std::domain_error if called on JSON values other than arrays;
|
@throw type_error.309 if called on JSON values other than arrays; example:
|
||||||
example: `"cannot use insert() with string"`
|
`"cannot use insert() with string"`
|
||||||
@throw invalid_iterator.202 if @a pos is not an iterator of *this;
|
@throw invalid_iterator.202 if @a pos is not an iterator of *this;
|
||||||
example: `"iterator does not fit current value"`
|
example: `"iterator does not fit current value"`
|
||||||
@throw invalid_iterator.210 if @a first and @a last do not belong to the
|
@throw invalid_iterator.210 if @a first and @a last do not belong to the
|
||||||
|
@ -5775,7 +5775,7 @@ class basic_json
|
||||||
// insert only works for arrays
|
// insert only works for arrays
|
||||||
if (not is_array())
|
if (not is_array())
|
||||||
{
|
{
|
||||||
JSON_THROW(std::domain_error("cannot use insert() with " + type_name()));
|
JSON_THROW(type_error(309, "cannot use insert() with " + type_name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if iterator pos fits to this JSON value
|
// check if iterator pos fits to this JSON value
|
||||||
|
@ -5813,8 +5813,8 @@ class basic_json
|
||||||
the end() iterator
|
the end() iterator
|
||||||
@param[in] ilist initializer list to insert the values from
|
@param[in] ilist initializer list to insert the values from
|
||||||
|
|
||||||
@throw std::domain_error if called on JSON values other than arrays;
|
@throw type_error.309 if called on JSON values other than arrays; example:
|
||||||
example: `"cannot use insert() with string"`
|
`"cannot use insert() with string"`
|
||||||
@throw invalid_iterator.202 if @a pos is not an iterator of *this;
|
@throw invalid_iterator.202 if @a pos is not an iterator of *this;
|
||||||
example: `"iterator does not fit current value"`
|
example: `"iterator does not fit current value"`
|
||||||
|
|
||||||
|
@ -5833,7 +5833,7 @@ class basic_json
|
||||||
// insert only works for arrays
|
// insert only works for arrays
|
||||||
if (not is_array())
|
if (not is_array())
|
||||||
{
|
{
|
||||||
JSON_THROW(std::domain_error("cannot use insert() with " + type_name()));
|
JSON_THROW(type_error(309, "cannot use insert() with " + type_name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if iterator pos fits to this JSON value
|
// check if iterator pos fits to this JSON value
|
||||||
|
|
|
@ -5655,7 +5655,7 @@ class basic_json
|
||||||
@param[in] val element to insert
|
@param[in] val element to insert
|
||||||
@return iterator pointing to the inserted @a val.
|
@return iterator pointing to the inserted @a val.
|
||||||
|
|
||||||
@throw std::domain_error if called on JSON values other than arrays;
|
@throw type_error.309 if called on JSON values other than arrays;
|
||||||
example: `"cannot use insert() with string"`
|
example: `"cannot use insert() with string"`
|
||||||
@throw invalid_iterator.202 if @a pos is not an iterator of *this;
|
@throw invalid_iterator.202 if @a pos is not an iterator of *this;
|
||||||
example: `"iterator does not fit current value"`
|
example: `"iterator does not fit current value"`
|
||||||
|
@ -5684,7 +5684,7 @@ class basic_json
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON_THROW(std::domain_error("cannot use insert() with " + type_name()));
|
JSON_THROW(type_error(309, "cannot use insert() with " + type_name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -5708,8 +5708,8 @@ class basic_json
|
||||||
@return iterator pointing to the first element inserted, or @a pos if
|
@return iterator pointing to the first element inserted, or @a pos if
|
||||||
`cnt==0`
|
`cnt==0`
|
||||||
|
|
||||||
@throw std::domain_error if called on JSON values other than arrays;
|
@throw type_error.309 if called on JSON values other than arrays; example:
|
||||||
example: `"cannot use insert() with string"`
|
`"cannot use insert() with string"`
|
||||||
@throw invalid_iterator.202 if @a pos is not an iterator of *this;
|
@throw invalid_iterator.202 if @a pos is not an iterator of *this;
|
||||||
example: `"iterator does not fit current value"`
|
example: `"iterator does not fit current value"`
|
||||||
|
|
||||||
|
@ -5737,7 +5737,7 @@ class basic_json
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON_THROW(std::domain_error("cannot use insert() with " + type_name()));
|
JSON_THROW(type_error(309, "cannot use insert() with " + type_name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -5750,8 +5750,8 @@ class basic_json
|
||||||
@param[in] first begin of the range of elements to insert
|
@param[in] first begin of the range of elements to insert
|
||||||
@param[in] last end of the range of elements to insert
|
@param[in] last end of the range of elements to insert
|
||||||
|
|
||||||
@throw std::domain_error if called on JSON values other than arrays;
|
@throw type_error.309 if called on JSON values other than arrays; example:
|
||||||
example: `"cannot use insert() with string"`
|
`"cannot use insert() with string"`
|
||||||
@throw invalid_iterator.202 if @a pos is not an iterator of *this;
|
@throw invalid_iterator.202 if @a pos is not an iterator of *this;
|
||||||
example: `"iterator does not fit current value"`
|
example: `"iterator does not fit current value"`
|
||||||
@throw invalid_iterator.210 if @a first and @a last do not belong to the
|
@throw invalid_iterator.210 if @a first and @a last do not belong to the
|
||||||
|
@ -5775,7 +5775,7 @@ class basic_json
|
||||||
// insert only works for arrays
|
// insert only works for arrays
|
||||||
if (not is_array())
|
if (not is_array())
|
||||||
{
|
{
|
||||||
JSON_THROW(std::domain_error("cannot use insert() with " + type_name()));
|
JSON_THROW(type_error(309, "cannot use insert() with " + type_name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if iterator pos fits to this JSON value
|
// check if iterator pos fits to this JSON value
|
||||||
|
@ -5813,8 +5813,8 @@ class basic_json
|
||||||
the end() iterator
|
the end() iterator
|
||||||
@param[in] ilist initializer list to insert the values from
|
@param[in] ilist initializer list to insert the values from
|
||||||
|
|
||||||
@throw std::domain_error if called on JSON values other than arrays;
|
@throw type_error.309 if called on JSON values other than arrays; example:
|
||||||
example: `"cannot use insert() with string"`
|
`"cannot use insert() with string"`
|
||||||
@throw invalid_iterator.202 if @a pos is not an iterator of *this;
|
@throw invalid_iterator.202 if @a pos is not an iterator of *this;
|
||||||
example: `"iterator does not fit current value"`
|
example: `"iterator does not fit current value"`
|
||||||
|
|
||||||
|
@ -5833,7 +5833,7 @@ class basic_json
|
||||||
// insert only works for arrays
|
// insert only works for arrays
|
||||||
if (not is_array())
|
if (not is_array())
|
||||||
{
|
{
|
||||||
JSON_THROW(std::domain_error("cannot use insert() with " + type_name()));
|
JSON_THROW(type_error(309, "cannot use insert() with " + type_name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if iterator pos fits to this JSON value
|
// check if iterator pos fits to this JSON value
|
||||||
|
|
|
@ -686,20 +686,20 @@ TEST_CASE("modifiers")
|
||||||
// call insert on a non-array type
|
// call insert on a non-array type
|
||||||
json j_nonarray = 3;
|
json j_nonarray = 3;
|
||||||
json j_yet_another_array = {"first", "second"};
|
json j_yet_another_array = {"first", "second"};
|
||||||
CHECK_THROWS_AS(j_nonarray.insert(j_nonarray.end(), 10), std::domain_error);
|
CHECK_THROWS_AS(j_nonarray.insert(j_nonarray.end(), 10), json::type_error);
|
||||||
CHECK_THROWS_AS(j_nonarray.insert(j_nonarray.end(), j_value), std::domain_error);
|
CHECK_THROWS_AS(j_nonarray.insert(j_nonarray.end(), j_value), json::type_error);
|
||||||
CHECK_THROWS_AS(j_nonarray.insert(j_nonarray.end(), 10, 11), std::domain_error);
|
CHECK_THROWS_AS(j_nonarray.insert(j_nonarray.end(), 10, 11), json::type_error);
|
||||||
CHECK_THROWS_AS(j_nonarray.insert(j_nonarray.end(), j_yet_another_array.begin(),
|
CHECK_THROWS_AS(j_nonarray.insert(j_nonarray.end(), j_yet_another_array.begin(),
|
||||||
j_yet_another_array.end()), std::domain_error);
|
j_yet_another_array.end()), json::type_error);
|
||||||
CHECK_THROWS_AS(j_nonarray.insert(j_nonarray.end(), {1, 2, 3, 4}), std::domain_error);
|
CHECK_THROWS_AS(j_nonarray.insert(j_nonarray.end(), {1, 2, 3, 4}), json::type_error);
|
||||||
|
|
||||||
CHECK_THROWS_WITH(j_nonarray.insert(j_nonarray.end(), 10), "cannot use insert() with number");
|
CHECK_THROWS_WITH(j_nonarray.insert(j_nonarray.end(), 10), "[json.exception.type_error.309] cannot use insert() with number");
|
||||||
CHECK_THROWS_WITH(j_nonarray.insert(j_nonarray.end(), j_value), "cannot use insert() with number");
|
CHECK_THROWS_WITH(j_nonarray.insert(j_nonarray.end(), j_value), "[json.exception.type_error.309] cannot use insert() with number");
|
||||||
CHECK_THROWS_WITH(j_nonarray.insert(j_nonarray.end(), 10, 11), "cannot use insert() with number");
|
CHECK_THROWS_WITH(j_nonarray.insert(j_nonarray.end(), 10, 11), "[json.exception.type_error.309] cannot use insert() with number");
|
||||||
CHECK_THROWS_WITH(j_nonarray.insert(j_nonarray.end(), j_yet_another_array.begin(),
|
CHECK_THROWS_WITH(j_nonarray.insert(j_nonarray.end(), j_yet_another_array.begin(),
|
||||||
j_yet_another_array.end()), "cannot use insert() with number");
|
j_yet_another_array.end()), "[json.exception.type_error.309] cannot use insert() with number");
|
||||||
CHECK_THROWS_WITH(j_nonarray.insert(j_nonarray.end(), {1, 2, 3, 4}),
|
CHECK_THROWS_WITH(j_nonarray.insert(j_nonarray.end(), {1, 2, 3, 4}),
|
||||||
"cannot use insert() with number");
|
"[json.exception.type_error.309] cannot use insert() with number");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue