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
70b2c3f4
Unverified
Commit
70b2c3f4
authored
Mar 05, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🔨
added user-defined exceptions 308
parent
2a9393af
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
26 deletions
+26
-26
src/json.hpp
src/json.hpp
+5
-5
src/json.hpp.re2c
src/json.hpp.re2c
+5
-5
test/src/unit-modifiers.cpp
test/src/unit-modifiers.cpp
+16
-16
No files found.
src/json.hpp
View file @
70b2c3f4
...
...
@@ -5374,7 +5374,7 @@ class basic_json
@param[in] val the value to add to the JSON array
@throw
std::domain_error
when called on a type other than JSON array or
@throw
type_error.308
when called on a type other than JSON array or
null; example: `"cannot use push_back() with number"`
@complexity Amortized constant.
...
...
@@ -5390,7 +5390,7 @@ class basic_json
// push_back only works for null objects or arrays
if
(
not
(
is_null
()
or
is_array
()))
{
JSON_THROW
(
std
::
domain_error
(
"cannot use push_back() with "
+
type_name
()));
JSON_THROW
(
type_error
(
308
,
"cannot use push_back() with "
+
type_name
()));
}
// transform null object into an array
...
...
@@ -5426,7 +5426,7 @@ class basic_json
// push_back only works for null objects or arrays
if
(
not
(
is_null
()
or
is_array
()))
{
JSON_THROW
(
std
::
domain_error
(
"cannot use push_back() with "
+
type_name
()));
JSON_THROW
(
type_error
(
308
,
"cannot use push_back() with "
+
type_name
()));
}
// transform null object into an array
...
...
@@ -5460,7 +5460,7 @@ class basic_json
@param[in] val the value to add to the JSON object
@throw
std::domain_error
when called on a type other than JSON object or
@throw
type_error.308
when called on a type other than JSON object or
null; example: `"cannot use push_back() with number"`
@complexity Logarithmic in the size of the container, O(log(`size()`)).
...
...
@@ -5476,7 +5476,7 @@ class basic_json
// push_back only works for null objects or objects
if
(
not
(
is_null
()
or
is_object
()))
{
JSON_THROW
(
std
::
domain_error
(
"cannot use push_back() with "
+
type_name
()));
JSON_THROW
(
type_error
(
308
,
"cannot use push_back() with "
+
type_name
()));
}
// transform null object into an object
...
...
src/json.hpp.re2c
View file @
70b2c3f4
...
...
@@ -5374,7 +5374,7 @@ class basic_json
@param[in] val the value to add to the JSON array
@throw
std::domain_error
when called on a type other than JSON array or
@throw
type_error.308
when called on a type other than JSON array or
null; example: `"cannot use push_back() with number"`
@complexity Amortized constant.
...
...
@@ -5390,7 +5390,7 @@ class basic_json
// push_back only works for null objects or arrays
if (not(is_null() or is_array()))
{
JSON_THROW(
std::domain_error(
"cannot use push_back() with " + type_name()));
JSON_THROW(
type_error(308,
"cannot use push_back() with " + type_name()));
}
// transform null object into an array
...
...
@@ -5426,7 +5426,7 @@ class basic_json
// push_back only works for null objects or arrays
if (not(is_null() or is_array()))
{
JSON_THROW(
std::domain_error(
"cannot use push_back() with " + type_name()));
JSON_THROW(
type_error(308,
"cannot use push_back() with " + type_name()));
}
// transform null object into an array
...
...
@@ -5460,7 +5460,7 @@ class basic_json
@param[in] val the value to add to the JSON object
@throw
std::domain_error
when called on a type other than JSON object or
@throw
type_error.308
when called on a type other than JSON object or
null; example: `"cannot use push_back() with number"`
@complexity Logarithmic in the size of the container, O(log(`size()`)).
...
...
@@ -5476,7 +5476,7 @@ class basic_json
// push_back only works for null objects or objects
if (not(is_null() or is_object()))
{
JSON_THROW(
std::domain_error(
"cannot use push_back() with " + type_name()));
JSON_THROW(
type_error(308,
"cannot use push_back() with " + type_name()));
}
// transform null object into an object
...
...
test/src/unit-modifiers.cpp
View file @
70b2c3f4
...
...
@@ -152,8 +152,8 @@ TEST_CASE("modifiers")
SECTION
(
"other type"
)
{
json
j
=
1
;
CHECK_THROWS_AS
(
j
.
push_back
(
"Hello"
),
std
::
domain
_error
);
CHECK_THROWS_WITH
(
j
.
push_back
(
"Hello"
),
"cannot use push_back() with number"
);
CHECK_THROWS_AS
(
j
.
push_back
(
"Hello"
),
json
::
type
_error
);
CHECK_THROWS_WITH
(
j
.
push_back
(
"Hello"
),
"
[json.exception.type_error.308]
cannot use push_back() with number"
);
}
}
...
...
@@ -182,8 +182,8 @@ TEST_CASE("modifiers")
{
json
j
=
1
;
json
k
(
"Hello"
);
CHECK_THROWS_AS
(
j
.
push_back
(
k
),
std
::
domain
_error
);
CHECK_THROWS_WITH
(
j
.
push_back
(
k
),
"cannot use push_back() with number"
);
CHECK_THROWS_AS
(
j
.
push_back
(
k
),
json
::
type
_error
);
CHECK_THROWS_WITH
(
j
.
push_back
(
k
),
"
[json.exception.type_error.308]
cannot use push_back() with number"
);
}
}
}
...
...
@@ -215,9 +215,9 @@ TEST_CASE("modifiers")
{
json
j
=
1
;
json
k
(
"Hello"
);
CHECK_THROWS_AS
(
j
.
push_back
(
json
::
object_t
::
value_type
({
"one"
,
1
})),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j
.
push_back
(
json
::
object_t
::
value_type
({
"one"
,
1
})),
json
::
type
_error
);
CHECK_THROWS_WITH
(
j
.
push_back
(
json
::
object_t
::
value_type
({
"one"
,
1
})),
"cannot use push_back() with number"
);
"
[json.exception.type_error.308]
cannot use push_back() with number"
);
}
}
...
...
@@ -252,8 +252,8 @@ TEST_CASE("modifiers")
CHECK
(
j
==
json
({{
"key1"
,
1
},
{
"key2"
,
"bar"
}}));
json
k
=
{{
"key1"
,
1
}};
CHECK_THROWS_AS
(
k
.
push_back
({
1
,
2
,
3
,
4
}),
std
::
domain
_error
);
CHECK_THROWS_WITH
(
k
.
push_back
({
1
,
2
,
3
,
4
}),
"cannot use push_back() with object"
);
CHECK_THROWS_AS
(
k
.
push_back
({
1
,
2
,
3
,
4
}),
json
::
type
_error
);
CHECK_THROWS_WITH
(
k
.
push_back
({
1
,
2
,
3
,
4
}),
"
[json.exception.type_error.308]
cannot use push_back() with object"
);
}
}
}
...
...
@@ -381,8 +381,8 @@ TEST_CASE("modifiers")
SECTION
(
"other type"
)
{
json
j
=
1
;
CHECK_THROWS_AS
(
j
+=
"Hello"
,
std
::
domain
_error
);
CHECK_THROWS_WITH
(
j
+=
"Hello"
,
"cannot use push_back() with number"
);
CHECK_THROWS_AS
(
j
+=
"Hello"
,
json
::
type
_error
);
CHECK_THROWS_WITH
(
j
+=
"Hello"
,
"
[json.exception.type_error.308]
cannot use push_back() with number"
);
}
}
...
...
@@ -411,8 +411,8 @@ TEST_CASE("modifiers")
{
json
j
=
1
;
json
k
(
"Hello"
);
CHECK_THROWS_AS
(
j
+=
k
,
std
::
domain
_error
);
CHECK_THROWS_WITH
(
j
+=
k
,
"cannot use push_back() with number"
);
CHECK_THROWS_AS
(
j
+=
k
,
json
::
type
_error
);
CHECK_THROWS_WITH
(
j
+=
k
,
"
[json.exception.type_error.308]
cannot use push_back() with number"
);
}
}
}
...
...
@@ -444,9 +444,9 @@ TEST_CASE("modifiers")
{
json
j
=
1
;
json
k
(
"Hello"
);
CHECK_THROWS_AS
(
j
+=
json
::
object_t
::
value_type
({
"one"
,
1
}),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j
+=
json
::
object_t
::
value_type
({
"one"
,
1
}),
json
::
type
_error
);
CHECK_THROWS_WITH
(
j
+=
json
::
object_t
::
value_type
({
"one"
,
1
}),
"cannot use push_back() with number"
);
"
[json.exception.type_error.308]
cannot use push_back() with number"
);
}
}
...
...
@@ -481,8 +481,8 @@ TEST_CASE("modifiers")
CHECK
(
j
==
json
({{
"key1"
,
1
},
{
"key2"
,
"bar"
}}));
json
k
=
{{
"key1"
,
1
}};
CHECK_THROWS_AS
((
k
+=
{
1
,
2
,
3
,
4
}),
std
::
domain
_error
);
CHECK_THROWS_WITH
((
k
+=
{
1
,
2
,
3
,
4
}),
"cannot use push_back() with object"
);
CHECK_THROWS_AS
((
k
+=
{
1
,
2
,
3
,
4
}),
json
::
type
_error
);
CHECK_THROWS_WITH
((
k
+=
{
1
,
2
,
3
,
4
}),
"
[json.exception.type_error.308]
cannot use push_back() with object"
);
}
}
}
...
...
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