Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
a4274d77
Unverified
Commit
a4274d77
authored
Mar 03, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🔨
added user-defined exceptions 205-206
parent
875b2da9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
50 additions
and
46 deletions
+50
-46
json.hpp
src/json.hpp
+8
-7
json.hpp.re2c
src/json.hpp.re2c
+8
-7
unit-constructor1.cpp
test/src/unit-constructor1.cpp
+6
-4
unit-element_access1.cpp
test/src/unit-element_access1.cpp
+20
-20
unit-iterators1.cpp
test/src/unit-iterators1.cpp
+0
-0
unit-iterators2.cpp
test/src/unit-iterators2.cpp
+8
-8
No files found.
src/json.hpp
View file @
a4274d77
...
@@ -2422,8 +2422,8 @@ class basic_json
...
@@ -2422,8 +2422,8 @@ class basic_json
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
@throw
std::domain_error
if called with a null value; example: `"cannot
@throw
invalid_iterator.206
if called with a null value; example: `"cannot
use
construct with iterators from null"`
construct with iterators from null"`
@complexity Linear in distance between @a first and @a last.
@complexity Linear in distance between @a first and @a last.
...
@@ -2519,7 +2519,8 @@ class basic_json
...
@@ -2519,7 +2519,8 @@ class basic_json
default
:
default
:
{
{
JSON_THROW
(
std
::
domain_error
(
"cannot use construct with iterators from "
+
first
.
m_object
->
type_name
()));
JSON_THROW
(
invalid_iterator
(
206
,
"cannot construct with iterators from "
+
first
.
m_object
->
type_name
()));
}
}
}
}
...
@@ -4402,7 +4403,7 @@ class basic_json
...
@@ -4402,7 +4403,7 @@ class basic_json
@throw invalid_iterator.202 if called on an iterator which does not belong
@throw invalid_iterator.202 if called on an iterator which does not belong
to the current JSON value; example: `"iterator does not fit current
to the current JSON value; example: `"iterator does not fit current
value"`
value"`
@throw
std::out_of_range
if called on a primitive type with invalid
@throw
invalid_iterator.205
if called on a primitive type with invalid
iterator (i.e., any iterator which is not `begin()`); example: `"iterator
iterator (i.e., any iterator which is not `begin()`); example: `"iterator
out of range"`
out of range"`
...
@@ -4448,7 +4449,7 @@ class basic_json
...
@@ -4448,7 +4449,7 @@ class basic_json
{
{
if
(
not
pos
.
m_it
.
primitive_iterator
.
is_begin
())
if
(
not
pos
.
m_it
.
primitive_iterator
.
is_begin
())
{
{
JSON_THROW
(
std
::
out_of_range
(
"iterator out of range"
));
JSON_THROW
(
invalid_iterator
(
205
,
"iterator out of range"
));
}
}
if
(
is_string
())
if
(
is_string
())
...
@@ -9625,7 +9626,7 @@ class basic_json
...
@@ -9625,7 +9626,7 @@ class basic_json
{
{
case
basic_json
:
:
value_t
::
object
:
case
basic_json
:
:
value_t
::
object
:
{
{
JSON_THROW
(
std
::
domain_error
(
"cannot use operator[] for object iterators"
));
JSON_THROW
(
invalid_iterator
(
208
,
"cannot use operator[] for object iterators"
));
}
}
case
basic_json
:
:
value_t
::
array
:
case
basic_json
:
:
value_t
::
array
:
...
@@ -9663,7 +9664,7 @@ class basic_json
...
@@ -9663,7 +9664,7 @@ class basic_json
return
m_it
.
object_iterator
->
first
;
return
m_it
.
object_iterator
->
first
;
}
}
JSON_THROW
(
std
::
domain_error
(
"cannot use key() for non-object iterators"
));
JSON_THROW
(
invalid_iterator
(
207
,
"cannot use key() for non-object iterators"
));
}
}
/*!
/*!
...
...
src/json.hpp.re2c
View file @
a4274d77
...
@@ -2422,8 +2422,8 @@ class basic_json
...
@@ -2422,8 +2422,8 @@ class basic_json
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
@throw
std::domain_error
if called with a null value; example: `"cannot
@throw
invalid_iterator.206
if called with a null value; example: `"cannot
use
construct with iterators from null"`
construct with iterators from null"`
@complexity Linear in distance between @a first and @a last.
@complexity Linear in distance between @a first and @a last.
...
@@ -2519,7 +2519,8 @@ class basic_json
...
@@ -2519,7 +2519,8 @@ class basic_json
default:
default:
{
{
JSON_THROW(std::domain_error("cannot use construct with iterators from " + first.m_object->type_name()));
JSON_THROW(invalid_iterator(206, "cannot construct with iterators from " +
first.m_object->type_name()));
}
}
}
}
...
@@ -4402,7 +4403,7 @@ class basic_json
...
@@ -4402,7 +4403,7 @@ class basic_json
@throw invalid_iterator.202 if called on an iterator which does not belong
@throw invalid_iterator.202 if called on an iterator which does not belong
to the current JSON value; example: `"iterator does not fit current
to the current JSON value; example: `"iterator does not fit current
value"`
value"`
@throw
std::out_of_range
if called on a primitive type with invalid
@throw
invalid_iterator.205
if called on a primitive type with invalid
iterator (i.e., any iterator which is not `begin()`); example: `"iterator
iterator (i.e., any iterator which is not `begin()`); example: `"iterator
out of range"`
out of range"`
...
@@ -4448,7 +4449,7 @@ class basic_json
...
@@ -4448,7 +4449,7 @@ class basic_json
{
{
if (not pos.m_it.primitive_iterator.is_begin())
if (not pos.m_it.primitive_iterator.is_begin())
{
{
JSON_THROW(
std::out_of_range(
"iterator out of range"));
JSON_THROW(
invalid_iterator(205,
"iterator out of range"));
}
}
if (is_string())
if (is_string())
...
@@ -9625,7 +9626,7 @@ class basic_json
...
@@ -9625,7 +9626,7 @@ class basic_json
{
{
case basic_json::value_t::object:
case basic_json::value_t::object:
{
{
JSON_THROW(
std::domain_error(
"cannot use operator[] for object iterators"));
JSON_THROW(
invalid_iterator(208,
"cannot use operator[] for object iterators"));
}
}
case basic_json::value_t::array:
case basic_json::value_t::array:
...
@@ -9663,7 +9664,7 @@ class basic_json
...
@@ -9663,7 +9664,7 @@ class basic_json
return m_it.object_iterator->first;
return m_it.object_iterator->first;
}
}
JSON_THROW(
std::domain_error(
"cannot use key() for non-object iterators"));
JSON_THROW(
invalid_iterator(207,
"cannot use key() for non-object iterators"));
}
}
/*!
/*!
...
...
test/src/unit-constructor1.cpp
View file @
a4274d77
...
@@ -1106,13 +1106,15 @@ TEST_CASE("constructors")
...
@@ -1106,13 +1106,15 @@ TEST_CASE("constructors")
{
{
{
{
json
j
;
json
j
;
CHECK_THROWS_AS
(
json
(
j
.
begin
(),
j
.
end
()),
std
::
domain_error
);
CHECK_THROWS_AS
(
json
(
j
.
begin
(),
j
.
end
()),
json
::
invalid_iterator
);
CHECK_THROWS_WITH
(
json
(
j
.
begin
(),
j
.
end
()),
"cannot use construct with iterators from null"
);
CHECK_THROWS_WITH
(
json
(
j
.
begin
(),
j
.
end
()),
"[json.exception.invalid_iterator.206] cannot construct with iterators from null"
);
}
}
{
{
json
j
;
json
j
;
CHECK_THROWS_AS
(
json
(
j
.
cbegin
(),
j
.
cend
()),
std
::
domain_error
);
CHECK_THROWS_AS
(
json
(
j
.
cbegin
(),
j
.
cend
()),
json
::
invalid_iterator
);
CHECK_THROWS_WITH
(
json
(
j
.
cbegin
(),
j
.
cend
()),
"cannot use construct with iterators from null"
);
CHECK_THROWS_WITH
(
json
(
j
.
cbegin
(),
j
.
cend
()),
"[json.exception.invalid_iterator.206] cannot construct with iterators from null"
);
}
}
}
}
...
...
test/src/unit-element_access1.cpp
View file @
a4274d77
...
@@ -689,13 +689,13 @@ TEST_CASE("element access 1")
...
@@ -689,13 +689,13 @@ TEST_CASE("element access 1")
{
{
{
{
json
j
=
"foo"
;
json
j
=
"foo"
;
CHECK_THROWS_AS
(
j
.
erase
(
j
.
end
()),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j
.
erase
(
j
.
end
()),
json
::
invalid_iterator
);
CHECK_THROWS_WITH
(
j
.
erase
(
j
.
end
()),
"iterator out of range"
);
CHECK_THROWS_WITH
(
j
.
erase
(
j
.
end
()),
"
[json.exception.invalid_iterator.205]
iterator out of range"
);
}
}
{
{
json
j
=
"bar"
;
json
j
=
"bar"
;
CHECK_THROWS_AS
(
j
.
erase
(
j
.
cend
()),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j
.
erase
(
j
.
cend
()),
json
::
invalid_iterator
);
CHECK_THROWS_WITH
(
j
.
erase
(
j
.
cend
()),
"iterator out of range"
);
CHECK_THROWS_WITH
(
j
.
erase
(
j
.
cend
()),
"
[json.exception.invalid_iterator.205]
iterator out of range"
);
}
}
}
}
...
@@ -703,13 +703,13 @@ TEST_CASE("element access 1")
...
@@ -703,13 +703,13 @@ TEST_CASE("element access 1")
{
{
{
{
json
j
=
false
;
json
j
=
false
;
CHECK_THROWS_AS
(
j
.
erase
(
j
.
end
()),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j
.
erase
(
j
.
end
()),
json
::
invalid_iterator
);
CHECK_THROWS_WITH
(
j
.
erase
(
j
.
end
()),
"iterator out of range"
);
CHECK_THROWS_WITH
(
j
.
erase
(
j
.
end
()),
"
[json.exception.invalid_iterator.205]
iterator out of range"
);
}
}
{
{
json
j
=
true
;
json
j
=
true
;
CHECK_THROWS_AS
(
j
.
erase
(
j
.
cend
()),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j
.
erase
(
j
.
cend
()),
json
::
invalid_iterator
);
CHECK_THROWS_WITH
(
j
.
erase
(
j
.
cend
()),
"iterator out of range"
);
CHECK_THROWS_WITH
(
j
.
erase
(
j
.
cend
()),
"
[json.exception.invalid_iterator.205]
iterator out of range"
);
}
}
}
}
...
@@ -717,13 +717,13 @@ TEST_CASE("element access 1")
...
@@ -717,13 +717,13 @@ TEST_CASE("element access 1")
{
{
{
{
json
j
=
17
;
json
j
=
17
;
CHECK_THROWS_AS
(
j
.
erase
(
j
.
end
()),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j
.
erase
(
j
.
end
()),
json
::
invalid_iterator
);
CHECK_THROWS_WITH
(
j
.
erase
(
j
.
end
()),
"iterator out of range"
);
CHECK_THROWS_WITH
(
j
.
erase
(
j
.
end
()),
"
[json.exception.invalid_iterator.205]
iterator out of range"
);
}
}
{
{
json
j
=
17
;
json
j
=
17
;
CHECK_THROWS_AS
(
j
.
erase
(
j
.
cend
()),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j
.
erase
(
j
.
cend
()),
json
::
invalid_iterator
);
CHECK_THROWS_WITH
(
j
.
erase
(
j
.
cend
()),
"iterator out of range"
);
CHECK_THROWS_WITH
(
j
.
erase
(
j
.
cend
()),
"
[json.exception.invalid_iterator.205]
iterator out of range"
);
}
}
}
}
...
@@ -731,13 +731,13 @@ TEST_CASE("element access 1")
...
@@ -731,13 +731,13 @@ TEST_CASE("element access 1")
{
{
{
{
json
j
=
17u
;
json
j
=
17u
;
CHECK_THROWS_AS
(
j
.
erase
(
j
.
end
()),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j
.
erase
(
j
.
end
()),
json
::
invalid_iterator
);
CHECK_THROWS_WITH
(
j
.
erase
(
j
.
end
()),
"iterator out of range"
);
CHECK_THROWS_WITH
(
j
.
erase
(
j
.
end
()),
"
[json.exception.invalid_iterator.205]
iterator out of range"
);
}
}
{
{
json
j
=
17u
;
json
j
=
17u
;
CHECK_THROWS_AS
(
j
.
erase
(
j
.
cend
()),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j
.
erase
(
j
.
cend
()),
json
::
invalid_iterator
);
CHECK_THROWS_WITH
(
j
.
erase
(
j
.
cend
()),
"iterator out of range"
);
CHECK_THROWS_WITH
(
j
.
erase
(
j
.
cend
()),
"
[json.exception.invalid_iterator.205]
iterator out of range"
);
}
}
}
}
...
@@ -745,13 +745,13 @@ TEST_CASE("element access 1")
...
@@ -745,13 +745,13 @@ TEST_CASE("element access 1")
{
{
{
{
json
j
=
23.42
;
json
j
=
23.42
;
CHECK_THROWS_AS
(
j
.
erase
(
j
.
end
()),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j
.
erase
(
j
.
end
()),
json
::
invalid_iterator
);
CHECK_THROWS_WITH
(
j
.
erase
(
j
.
end
()),
"iterator out of range"
);
CHECK_THROWS_WITH
(
j
.
erase
(
j
.
end
()),
"
[json.exception.invalid_iterator.205]
iterator out of range"
);
}
}
{
{
json
j
=
23.42
;
json
j
=
23.42
;
CHECK_THROWS_AS
(
j
.
erase
(
j
.
cend
()),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j
.
erase
(
j
.
cend
()),
json
::
invalid_iterator
);
CHECK_THROWS_WITH
(
j
.
erase
(
j
.
cend
()),
"iterator out of range"
);
CHECK_THROWS_WITH
(
j
.
erase
(
j
.
cend
()),
"
[json.exception.invalid_iterator.205]
iterator out of range"
);
}
}
}
}
}
}
...
...
test/src/unit-iterators1.cpp
View file @
a4274d77
This diff is collapsed.
Click to expand it.
test/src/unit-iterators2.cpp
View file @
a4274d77
...
@@ -380,17 +380,17 @@ TEST_CASE("iterators 2")
...
@@ -380,17 +380,17 @@ TEST_CASE("iterators 2")
{
{
{
{
auto
it
=
j_object
.
begin
();
auto
it
=
j_object
.
begin
();
CHECK_THROWS_AS
(
it
[
0
],
std
::
domain_err
or
);
CHECK_THROWS_AS
(
it
[
0
],
json
::
invalid_iterat
or
);
CHECK_THROWS_AS
(
it
[
1
],
std
::
domain_err
or
);
CHECK_THROWS_AS
(
it
[
1
],
json
::
invalid_iterat
or
);
CHECK_THROWS_WITH
(
it
[
0
],
"cannot use operator[] for object iterators"
);
CHECK_THROWS_WITH
(
it
[
0
],
"
[json.exception.invalid_iterator.208]
cannot use operator[] for object iterators"
);
CHECK_THROWS_WITH
(
it
[
1
],
"cannot use operator[] for object iterators"
);
CHECK_THROWS_WITH
(
it
[
1
],
"
[json.exception.invalid_iterator.208]
cannot use operator[] for object iterators"
);
}
}
{
{
auto
it
=
j_object
.
cbegin
();
auto
it
=
j_object
.
cbegin
();
CHECK_THROWS_AS
(
it
[
0
],
std
::
domain_err
or
);
CHECK_THROWS_AS
(
it
[
0
],
json
::
invalid_iterat
or
);
CHECK_THROWS_AS
(
it
[
1
],
std
::
domain_err
or
);
CHECK_THROWS_AS
(
it
[
1
],
json
::
invalid_iterat
or
);
CHECK_THROWS_WITH
(
it
[
0
],
"cannot use operator[] for object iterators"
);
CHECK_THROWS_WITH
(
it
[
0
],
"
[json.exception.invalid_iterator.208]
cannot use operator[] for object iterators"
);
CHECK_THROWS_WITH
(
it
[
1
],
"cannot use operator[] for object iterators"
);
CHECK_THROWS_WITH
(
it
[
1
],
"
[json.exception.invalid_iterator.208]
cannot use operator[] for object iterators"
);
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment