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
2a9393af
Unverified
Commit
2a9393af
authored
Mar 05, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🔨
added user-defined exceptions 307
parent
bb740c43
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
32 deletions
+38
-32
json.hpp
src/json.hpp
+10
-10
json.hpp.re2c
src/json.hpp.re2c
+10
-10
unit-element_access1.cpp
test/src/unit-element_access1.cpp
+0
-0
unit-element_access2.cpp
test/src/unit-element_access2.cpp
+18
-12
No files found.
src/json.hpp
View file @
2a9393af
...
@@ -4397,8 +4397,8 @@ class basic_json
...
@@ -4397,8 +4397,8 @@ class basic_json
@post Invalidates iterators and references at or after the point of the
@post Invalidates iterators and references at or after the point of the
erase, including the `end()` iterator.
erase, including the `end()` iterator.
@throw
std::domain_error if called on a `null` value; example: `"cannot
@throw
type_error.307 if called on a `null` value; example: `"cannot use
use
erase() with null"`
erase() with null"`
@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"`
...
@@ -4478,7 +4478,7 @@ class basic_json
...
@@ -4478,7 +4478,7 @@ class basic_json
default
:
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
...
@@ -4505,8 +4505,8 @@ class basic_json
@post Invalidates iterators and references at or after the point of the
@post Invalidates iterators and references at or after the point of the
erase, including the `end()` iterator.
erase, including the `end()` iterator.
@throw
std::domain_error if called on a `null` value; example: `"cannot
@throw
type_error.307 if called on a `null` value; example: `"cannot use
use
erase() with null"`
erase() with null"`
@throw invalid_iterator.203 if called on iterators which does not belong
@throw invalid_iterator.203 if called on iterators which does not belong
to the current JSON value; example: `"iterators do not fit current value"`
to the current JSON value; example: `"iterators do not fit current value"`
@throw invalid_iterator.204 if called on a primitive type with invalid
@throw invalid_iterator.204 if called on a primitive type with invalid
...
@@ -4587,7 +4587,7 @@ class basic_json
...
@@ -4587,7 +4587,7 @@ class basic_json
default
:
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
...
@@ -4608,7 +4608,7 @@ class basic_json
@post References and iterators to the erased elements are invalidated.
@post References and iterators to the erased elements are invalidated.
Other references and iterators are not affected.
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"`
example: `"cannot use erase() with null"`
@complexity `log(size()) + count(key)`
@complexity `log(size()) + count(key)`
...
@@ -4631,7 +4631,7 @@ class basic_json
...
@@ -4631,7 +4631,7 @@ class basic_json
return
m_value
.
object
->
erase
(
key
);
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
...
@@ -4641,7 +4641,7 @@ class basic_json
@param[in] idx index of the element to remove
@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"`
example: `"cannot use erase() with null"`
@throw std::out_of_range when `idx >= size()`; example: `"array index 17
@throw std::out_of_range when `idx >= size()`; example: `"array index 17
is out of range"`
is out of range"`
...
@@ -4672,7 +4672,7 @@ class basic_json
...
@@ -4672,7 +4672,7 @@ class basic_json
}
}
else
else
{
{
JSON_THROW
(
std
::
domain_error
(
"cannot use erase() with "
+
type_name
()));
JSON_THROW
(
type_error
(
307
,
"cannot use erase() with "
+
type_name
()));
}
}
}
}
...
...
src/json.hpp.re2c
View file @
2a9393af
...
@@ -4397,8 +4397,8 @@ class basic_json
...
@@ -4397,8 +4397,8 @@ class basic_json
@post Invalidates iterators and references at or after the point of the
@post Invalidates iterators and references at or after the point of the
erase, including the `end()` iterator.
erase, including the `end()` iterator.
@throw
std::domain_error if called on a `null` value; example: `"cannot
@throw
type_error.307 if called on a `null` value; example: `"cannot use
use
erase() with null"`
erase() with null"`
@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"`
...
@@ -4478,7 +4478,7 @@ class basic_json
...
@@ -4478,7 +4478,7 @@ class basic_json
default:
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
...
@@ -4505,8 +4505,8 @@ class basic_json
@post Invalidates iterators and references at or after the point of the
@post Invalidates iterators and references at or after the point of the
erase, including the `end()` iterator.
erase, including the `end()` iterator.
@throw
std::domain_error if called on a `null` value; example: `"cannot
@throw
type_error.307 if called on a `null` value; example: `"cannot use
use
erase() with null"`
erase() with null"`
@throw invalid_iterator.203 if called on iterators which does not belong
@throw invalid_iterator.203 if called on iterators which does not belong
to the current JSON value; example: `"iterators do not fit current value"`
to the current JSON value; example: `"iterators do not fit current value"`
@throw invalid_iterator.204 if called on a primitive type with invalid
@throw invalid_iterator.204 if called on a primitive type with invalid
...
@@ -4587,7 +4587,7 @@ class basic_json
...
@@ -4587,7 +4587,7 @@ class basic_json
default:
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
...
@@ -4608,7 +4608,7 @@ class basic_json
@post References and iterators to the erased elements are invalidated.
@post References and iterators to the erased elements are invalidated.
Other references and iterators are not affected.
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"`
example: `"cannot use erase() with null"`
@complexity `log(size()) + count(key)`
@complexity `log(size()) + count(key)`
...
@@ -4631,7 +4631,7 @@ class basic_json
...
@@ -4631,7 +4631,7 @@ class basic_json
return m_value.object->erase(key);
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
...
@@ -4641,7 +4641,7 @@ class basic_json
@param[in] idx index of the element to remove
@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"`
example: `"cannot use erase() with null"`
@throw std::out_of_range when `idx >= size()`; example: `"array index 17
@throw std::out_of_range when `idx >= size()`; example: `"array index 17
is out of range"`
is out of range"`
...
@@ -4672,7 +4672,7 @@ class basic_json
...
@@ -4672,7 +4672,7 @@ class basic_json
}
}
else
else
{
{
JSON_THROW(
std::domain_error(
"cannot use erase() with " + type_name()));
JSON_THROW(
type_error(307,
"cannot use erase() with " + type_name()));
}
}
}
}
...
...
test/src/unit-element_access1.cpp
View file @
2a9393af
This diff is collapsed.
Click to expand it.
test/src/unit-element_access2.cpp
View file @
2a9393af
...
@@ -757,43 +757,49 @@ TEST_CASE("element access 2")
...
@@ -757,43 +757,49 @@ TEST_CASE("element access 2")
SECTION
(
"null"
)
SECTION
(
"null"
)
{
{
json
j_nonobject
(
json
::
value_t
::
null
);
json
j_nonobject
(
json
::
value_t
::
null
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
json
::
type_error
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
"foo"
),
"cannot use erase() with null"
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
"foo"
),
"[json.exception.type_error.307] cannot use erase() with null"
);
}
}
SECTION
(
"boolean"
)
SECTION
(
"boolean"
)
{
{
json
j_nonobject
(
json
::
value_t
::
boolean
);
json
j_nonobject
(
json
::
value_t
::
boolean
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
json
::
type_error
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
"foo"
),
"cannot use erase() with boolean"
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
"foo"
),
"[json.exception.type_error.307] cannot use erase() with boolean"
);
}
}
SECTION
(
"string"
)
SECTION
(
"string"
)
{
{
json
j_nonobject
(
json
::
value_t
::
string
);
json
j_nonobject
(
json
::
value_t
::
string
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
json
::
type_error
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
"foo"
),
"cannot use erase() with string"
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
"foo"
),
"[json.exception.type_error.307] cannot use erase() with string"
);
}
}
SECTION
(
"array"
)
SECTION
(
"array"
)
{
{
json
j_nonobject
(
json
::
value_t
::
array
);
json
j_nonobject
(
json
::
value_t
::
array
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
json
::
type_error
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
"foo"
),
"cannot use erase() with array"
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
"foo"
),
"[json.exception.type_error.307] cannot use erase() with array"
);
}
}
SECTION
(
"number (integer)"
)
SECTION
(
"number (integer)"
)
{
{
json
j_nonobject
(
json
::
value_t
::
number_integer
);
json
j_nonobject
(
json
::
value_t
::
number_integer
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
json
::
type_error
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
"foo"
),
"cannot use erase() with number"
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
"foo"
),
"[json.exception.type_error.307] cannot use erase() with number"
);
}
}
SECTION
(
"number (floating-point)"
)
SECTION
(
"number (floating-point)"
)
{
{
json
j_nonobject
(
json
::
value_t
::
number_float
);
json
j_nonobject
(
json
::
value_t
::
number_float
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
json
::
type_error
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
"foo"
),
"cannot use erase() with number"
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
"foo"
),
"[json.exception.type_error.307] cannot use erase() with number"
);
}
}
}
}
}
}
...
...
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