Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
875b2da9
Unverified
Commit
875b2da9
authored
Mar 03, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🔨
added user-defined exceptions 203-204
parent
9381f6c4
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
118 additions
and
118 deletions
+118
-118
src/json.hpp
src/json.hpp
+7
-7
src/json.hpp.re2c
src/json.hpp.re2c
+7
-7
test/src/unit-constructor1.cpp
test/src/unit-constructor1.cpp
+40
-40
test/src/unit-element_access1.cpp
test/src/unit-element_access1.cpp
+52
-52
test/src/unit-element_access2.cpp
test/src/unit-element_access2.cpp
+12
-12
No files found.
src/json.hpp
View file @
875b2da9
...
...
@@ -2418,7 +2418,7 @@ class basic_json
@throw invalid_iterator.201 if iterators are not compatible; that is, do
not belong to the same JSON value; example: `"iterators are not
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;
example: `"iterators out of range"`
@throw std::bad_alloc if allocation for object, array, or string fails
...
...
@@ -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
())
{
JSON_THROW
(
std
::
out_of_range
(
"iterators out of range"
));
JSON_THROW
(
invalid_iterator
(
204
,
"iterators out of range"
));
}
break
;
}
...
...
@@ -4507,9 +4507,9 @@ class basic_json
@throw std::domain_error if called on a `null` value; example: `"cannot
use erase() with null"`
@throw
std::domain_error if called on iterators which does not belong 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.203 if called on iterators which does not belong
t
o t
he current JSON value; example: `"iterators do not fit current value"`
@throw
invalid_iterator.204
if called on a primitive type with invalid
iterators (i.e., if `first != begin()` and `last != end()`); example:
`"iterators out of range"`
...
...
@@ -4540,7 +4540,7 @@ class basic_json
// make sure iterator fits the current value
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
();
...
...
@@ -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
())
{
JSON_THROW
(
std
::
out_of_range
(
"iterators out of range"
));
JSON_THROW
(
invalid_iterator
(
204
,
"iterators out of range"
));
}
if
(
is_string
())
...
...
src/json.hpp.re2c
View file @
875b2da9
...
...
@@ -2418,7 +2418,7 @@ class basic_json
@throw invalid_iterator.201 if iterators are not compatible; that is, do
not belong to the same JSON value; example: `"iterators are not
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;
example: `"iterators out of range"`
@throw std::bad_alloc if allocation for object, array, or string fails
...
...
@@ -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())
{
JSON_THROW(
std::out_of_range(
"iterators out of range"));
JSON_THROW(
invalid_iterator(204,
"iterators out of range"));
}
break;
}
...
...
@@ -4507,9 +4507,9 @@ class basic_json
@throw std::domain_error if called on a `null` value; example: `"cannot
use erase() with null"`
@throw
std::domain_error if called on iterators which does not belong 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.203 if called on iterators which does not belong
t
o t
he current JSON value; example: `"iterators do not fit current value"`
@throw
invalid_iterator.204
if called on a primitive type with invalid
iterators (i.e., if `first != begin()` and `last != end()`); example:
`"iterators out of range"`
...
...
@@ -4540,7 +4540,7 @@ class basic_json
// make sure iterator fits the current value
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();
...
...
@@ -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())
{
JSON_THROW(
std::out_of_range(
"iterators out of range"));
JSON_THROW(
invalid_iterator(204,
"iterators out of range"));
}
if (is_string())
...
...
test/src/unit-constructor1.cpp
View file @
875b2da9
...
...
@@ -1193,17 +1193,17 @@ TEST_CASE("constructors")
{
{
json
j
=
"foo"
;
CHECK_THROWS_AS
(
json
(
j
.
end
(),
j
.
end
()),
std
::
out_of_range
);
CHECK_THROWS_AS
(
json
(
j
.
begin
(),
j
.
begin
()),
std
::
out_of_range
);
CHECK_THROWS_WITH
(
json
(
j
.
end
(),
j
.
end
()),
"iterators out of range"
);
CHECK_THROWS_WITH
(
json
(
j
.
begin
(),
j
.
begin
()),
"iterators out of range"
);
CHECK_THROWS_AS
(
json
(
j
.
end
(),
j
.
end
()),
json
::
invalid_iterator
);
CHECK_THROWS_AS
(
json
(
j
.
begin
(),
j
.
begin
()),
json
::
invalid_iterator
);
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
()),
"
[json.exception.invalid_iterator.204]
iterators out of range"
);
}
{
json
j
=
"bar"
;
CHECK_THROWS_AS
(
json
(
j
.
cend
(),
j
.
cend
()),
std
::
out_of_range
);
CHECK_THROWS_AS
(
json
(
j
.
cbegin
(),
j
.
cbegin
()),
std
::
out_of_range
);
CHECK_THROWS_WITH
(
json
(
j
.
cend
(),
j
.
cend
()),
"iterators out of range"
);
CHECK_THROWS_WITH
(
json
(
j
.
cbegin
(),
j
.
cbegin
()),
"iterators out of range"
);
CHECK_THROWS_AS
(
json
(
j
.
cend
(),
j
.
cend
()),
json
::
invalid_iterator
);
CHECK_THROWS_AS
(
json
(
j
.
cbegin
(),
j
.
cbegin
()),
json
::
invalid_iterator
);
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
()),
"
[json.exception.invalid_iterator.204]
iterators out of range"
);
}
}
...
...
@@ -1211,17 +1211,17 @@ TEST_CASE("constructors")
{
{
json
j
=
false
;
CHECK_THROWS_AS
(
json
(
j
.
end
(),
j
.
end
()),
std
::
out_of_range
);
CHECK_THROWS_AS
(
json
(
j
.
begin
(),
j
.
begin
()),
std
::
out_of_range
);
CHECK_THROWS_WITH
(
json
(
j
.
end
(),
j
.
end
()),
"iterators out of range"
);
CHECK_THROWS_WITH
(
json
(
j
.
begin
(),
j
.
begin
()),
"iterators out of range"
);
CHECK_THROWS_AS
(
json
(
j
.
end
(),
j
.
end
()),
json
::
invalid_iterator
);
CHECK_THROWS_AS
(
json
(
j
.
begin
(),
j
.
begin
()),
json
::
invalid_iterator
);
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
()),
"
[json.exception.invalid_iterator.204]
iterators out of range"
);
}
{
json
j
=
true
;
CHECK_THROWS_AS
(
json
(
j
.
cend
(),
j
.
cend
()),
std
::
out_of_range
);
CHECK_THROWS_AS
(
json
(
j
.
cbegin
(),
j
.
cbegin
()),
std
::
out_of_range
);
CHECK_THROWS_WITH
(
json
(
j
.
cend
(),
j
.
cend
()),
"iterators out of range"
);
CHECK_THROWS_WITH
(
json
(
j
.
cbegin
(),
j
.
cbegin
()),
"iterators out of range"
);
CHECK_THROWS_AS
(
json
(
j
.
cend
(),
j
.
cend
()),
json
::
invalid_iterator
);
CHECK_THROWS_AS
(
json
(
j
.
cbegin
(),
j
.
cbegin
()),
json
::
invalid_iterator
);
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
()),
"
[json.exception.invalid_iterator.204]
iterators out of range"
);
}
}
...
...
@@ -1229,17 +1229,17 @@ TEST_CASE("constructors")
{
{
json
j
=
17
;
CHECK_THROWS_AS
(
json
(
j
.
end
(),
j
.
end
()),
std
::
out_of_range
);
CHECK_THROWS_AS
(
json
(
j
.
begin
(),
j
.
begin
()),
std
::
out_of_range
);
CHECK_THROWS_WITH
(
json
(
j
.
end
(),
j
.
end
()),
"iterators out of range"
);
CHECK_THROWS_WITH
(
json
(
j
.
begin
(),
j
.
begin
()),
"iterators out of range"
);
CHECK_THROWS_AS
(
json
(
j
.
end
(),
j
.
end
()),
json
::
invalid_iterator
);
CHECK_THROWS_AS
(
json
(
j
.
begin
(),
j
.
begin
()),
json
::
invalid_iterator
);
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
()),
"
[json.exception.invalid_iterator.204]
iterators out of range"
);
}
{
json
j
=
17
;
CHECK_THROWS_AS
(
json
(
j
.
cend
(),
j
.
cend
()),
std
::
out_of_range
);
CHECK_THROWS_AS
(
json
(
j
.
cbegin
(),
j
.
cbegin
()),
std
::
out_of_range
);
CHECK_THROWS_WITH
(
json
(
j
.
cend
(),
j
.
cend
()),
"iterators out of range"
);
CHECK_THROWS_WITH
(
json
(
j
.
cbegin
(),
j
.
cbegin
()),
"iterators out of range"
);
CHECK_THROWS_AS
(
json
(
j
.
cend
(),
j
.
cend
()),
json
::
invalid_iterator
);
CHECK_THROWS_AS
(
json
(
j
.
cbegin
(),
j
.
cbegin
()),
json
::
invalid_iterator
);
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
()),
"
[json.exception.invalid_iterator.204]
iterators out of range"
);
}
}
...
...
@@ -1247,17 +1247,17 @@ TEST_CASE("constructors")
{
{
json
j
=
17u
;
CHECK_THROWS_AS
(
json
(
j
.
end
(),
j
.
end
()),
std
::
out_of_range
);
CHECK_THROWS_AS
(
json
(
j
.
begin
(),
j
.
begin
()),
std
::
out_of_range
);
CHECK_THROWS_WITH
(
json
(
j
.
end
(),
j
.
end
()),
"iterators out of range"
);
CHECK_THROWS_WITH
(
json
(
j
.
begin
(),
j
.
begin
()),
"iterators out of range"
);
CHECK_THROWS_AS
(
json
(
j
.
end
(),
j
.
end
()),
json
::
invalid_iterator
);
CHECK_THROWS_AS
(
json
(
j
.
begin
(),
j
.
begin
()),
json
::
invalid_iterator
);
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
()),
"
[json.exception.invalid_iterator.204]
iterators out of range"
);
}
{
json
j
=
17u
;
CHECK_THROWS_AS
(
json
(
j
.
cend
(),
j
.
cend
()),
std
::
out_of_range
);
CHECK_THROWS_AS
(
json
(
j
.
cbegin
(),
j
.
cbegin
()),
std
::
out_of_range
);
CHECK_THROWS_WITH
(
json
(
j
.
cend
(),
j
.
cend
()),
"iterators out of range"
);
CHECK_THROWS_WITH
(
json
(
j
.
cbegin
(),
j
.
cbegin
()),
"iterators out of range"
);
CHECK_THROWS_AS
(
json
(
j
.
cend
(),
j
.
cend
()),
json
::
invalid_iterator
);
CHECK_THROWS_AS
(
json
(
j
.
cbegin
(),
j
.
cbegin
()),
json
::
invalid_iterator
);
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
()),
"
[json.exception.invalid_iterator.204]
iterators out of range"
);
}
}
...
...
@@ -1265,17 +1265,17 @@ TEST_CASE("constructors")
{
{
json
j
=
23.42
;
CHECK_THROWS_AS
(
json
(
j
.
end
(),
j
.
end
()),
std
::
out_of_range
);
CHECK_THROWS_AS
(
json
(
j
.
begin
(),
j
.
begin
()),
std
::
out_of_range
);
CHECK_THROWS_WITH
(
json
(
j
.
end
(),
j
.
end
()),
"iterators out of range"
);
CHECK_THROWS_WITH
(
json
(
j
.
begin
(),
j
.
begin
()),
"iterators out of range"
);
CHECK_THROWS_AS
(
json
(
j
.
end
(),
j
.
end
()),
json
::
invalid_iterator
);
CHECK_THROWS_AS
(
json
(
j
.
begin
(),
j
.
begin
()),
json
::
invalid_iterator
);
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
()),
"
[json.exception.invalid_iterator.204]
iterators out of range"
);
}
{
json
j
=
23.42
;
CHECK_THROWS_AS
(
json
(
j
.
cend
(),
j
.
cend
()),
std
::
out_of_range
);
CHECK_THROWS_AS
(
json
(
j
.
cbegin
(),
j
.
cbegin
()),
std
::
out_of_range
);
CHECK_THROWS_WITH
(
json
(
j
.
cend
(),
j
.
cend
()),
"iterators out of range"
);
CHECK_THROWS_WITH
(
json
(
j
.
cbegin
(),
j
.
cbegin
()),
"iterators out of range"
);
CHECK_THROWS_AS
(
json
(
j
.
cend
(),
j
.
cend
()),
json
::
invalid_iterator
);
CHECK_THROWS_AS
(
json
(
j
.
cbegin
(),
j
.
cbegin
()),
json
::
invalid_iterator
);
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
()),
"
[json.exception.invalid_iterator.204]
iterators out of range"
);
}
}
}
...
...
test/src/unit-element_access1.cpp
View file @
875b2da9
This diff is collapsed.
Click to expand it.
test/src/unit-element_access2.cpp
View file @
875b2da9
...
...
@@ -686,33 +686,33 @@ TEST_CASE("element access 2")
json
jobject
=
{{
"a"
,
"a"
},
{
"b"
,
1
},
{
"c"
,
17u
},
{
"d"
,
false
},
{
"e"
,
true
}};
json
jobject2
=
{{
"a"
,
"a"
},
{
"b"
,
1
},
{
"c"
,
17u
}};
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
begin
()),
json
::
invalid_iterator
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject
.
begin
(),
jobject2
.
end
()),
std
::
domain_err
or
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
begin
(),
jobject
.
end
()),
std
::
domain_err
or
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
begin
(),
jobject2
.
end
()),
std
::
domain_err
or
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject
.
begin
(),
jobject2
.
end
()),
json
::
invalid_iterat
or
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
begin
(),
jobject
.
end
()),
json
::
invalid_iterat
or
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
begin
(),
jobject2
.
end
()),
json
::
invalid_iterat
or
);
CHECK_THROWS_WITH
(
jobject
.
erase
(
jobject2
.
begin
()),
"[json.exception.invalid_iterator.202] iterator does not fit current value"
);
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
()),
"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
()),
"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
jobject2
=
{{
"a"
,
"a"
},
{
"b"
,
1
},
{
"c"
,
17u
}};
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
cbegin
()),
json
::
invalid_iterator
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject
.
cbegin
(),
jobject2
.
cend
()),
std
::
domain_err
or
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
cbegin
(),
jobject
.
cend
()),
std
::
domain_err
or
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
cbegin
(),
jobject2
.
cend
()),
std
::
domain_err
or
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject
.
cbegin
(),
jobject2
.
cend
()),
json
::
invalid_iterat
or
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
cbegin
(),
jobject
.
cend
()),
json
::
invalid_iterat
or
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
cbegin
(),
jobject2
.
cend
()),
json
::
invalid_iterat
or
);
CHECK_THROWS_WITH
(
jobject
.
erase
(
jobject2
.
cbegin
()),
"[json.exception.invalid_iterator.202] iterator does not fit current value"
);
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
()),
"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
()),
"iterators do not fit current value"
);
"
[json.exception.invalid_iterator.203]
iterators do not fit current value"
);
}
}
}
...
...
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