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
aa842b4a
Unverified
Commit
aa842b4a
authored
Mar 05, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🔨
added user-defined exceptions 305
parent
f473f74f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
60 deletions
+60
-60
json.hpp
src/json.hpp
+17
-17
json.hpp.re2c
src/json.hpp.re2c
+17
-17
unit-element_access1.cpp
test/src/unit-element_access1.cpp
+26
-26
unit-element_access2.cpp
test/src/unit-element_access2.cpp
+0
-0
No files found.
src/json.hpp
View file @
aa842b4a
...
@@ -3828,8 +3828,8 @@ class basic_json
...
@@ -3828,8 +3828,8 @@ class basic_json
@return reference to the element at index @a idx
@return reference to the element at index @a idx
@throw
std::domain_error if JSON is not an array or null; example:
@throw
type_error.305 if JSON is not an array or null; example: `"cannot
`"cannot use operator[] with string"`
use operator[] with string"
@complexity Constant if @a idx is in the range of the array. Otherwise
@complexity Constant if @a idx is in the range of the array. Otherwise
linear in `idx - size()`.
linear in `idx - size()`.
...
@@ -3864,7 +3864,7 @@ class basic_json
...
@@ -3864,7 +3864,7 @@ class basic_json
return
m_value
.
array
->
operator
[](
idx
);
return
m_value
.
array
->
operator
[](
idx
);
}
}
JSON_THROW
(
std
::
domain_error
(
"cannot use operator[] with "
+
type_name
()));
JSON_THROW
(
type_error
(
305
,
"cannot use operator[] with "
+
type_name
()));
}
}
/*!
/*!
...
@@ -3876,7 +3876,7 @@ class basic_json
...
@@ -3876,7 +3876,7 @@ class basic_json
@return const reference to the element at index @a idx
@return const reference to the element at index @a idx
@throw
std::domain_error
if JSON is not an array; example: `"cannot use
@throw
type_error.305
if JSON is not an array; example: `"cannot use
operator[] with null"`
operator[] with null"`
@complexity Constant.
@complexity Constant.
...
@@ -3894,7 +3894,7 @@ class basic_json
...
@@ -3894,7 +3894,7 @@ class basic_json
return
m_value
.
array
->
operator
[](
idx
);
return
m_value
.
array
->
operator
[](
idx
);
}
}
JSON_THROW
(
std
::
domain_error
(
"cannot use operator[] with "
+
type_name
()));
JSON_THROW
(
type_error
(
305
,
"cannot use operator[] with "
+
type_name
()));
}
}
/*!
/*!
...
@@ -3910,8 +3910,8 @@ class basic_json
...
@@ -3910,8 +3910,8 @@ class basic_json
@return reference to the element at key @a key
@return reference to the element at key @a key
@throw
std::domain_error if JSON is not an object or null; example:
@throw
type_error.305 if JSON is not an object or null; example: `"cannot
`"cannot
use operator[] with string"`
use operator[] with string"`
@complexity Logarithmic in the size of the container.
@complexity Logarithmic in the size of the container.
...
@@ -3940,7 +3940,7 @@ class basic_json
...
@@ -3940,7 +3940,7 @@ class basic_json
return
m_value
.
object
->
operator
[](
key
);
return
m_value
.
object
->
operator
[](
key
);
}
}
JSON_THROW
(
std
::
domain_error
(
"cannot use operator[] with "
+
type_name
()));
JSON_THROW
(
type_error
(
305
,
"cannot use operator[] with "
+
type_name
()));
}
}
/*!
/*!
...
@@ -3959,7 +3959,7 @@ class basic_json
...
@@ -3959,7 +3959,7 @@ class basic_json
@pre The element with key @a key must exist. **This precondition is
@pre The element with key @a key must exist. **This precondition is
enforced with an assertion.**
enforced with an assertion.**
@throw
std::domain_error
if JSON is not an object; example: `"cannot use
@throw
type_error.305
if JSON is not an object; example: `"cannot use
operator[] with null"`
operator[] with null"`
@complexity Logarithmic in the size of the container.
@complexity Logarithmic in the size of the container.
...
@@ -3982,7 +3982,7 @@ class basic_json
...
@@ -3982,7 +3982,7 @@ class basic_json
return
m_value
.
object
->
find
(
key
)
->
second
;
return
m_value
.
object
->
find
(
key
)
->
second
;
}
}
JSON_THROW
(
std
::
domain_error
(
"cannot use operator[] with "
+
type_name
()));
JSON_THROW
(
type_error
(
305
,
"cannot use operator[] with "
+
type_name
()));
}
}
/*!
/*!
...
@@ -3998,8 +3998,8 @@ class basic_json
...
@@ -3998,8 +3998,8 @@ class basic_json
@return reference to the element at key @a key
@return reference to the element at key @a key
@throw
std::domain_error if JSON is not an object or null; example:
@throw
type_error.305 if JSON is not an object or null; example: `"cannot
`"cannot
use operator[] with string"`
use operator[] with string"`
@complexity Logarithmic in the size of the container.
@complexity Logarithmic in the size of the container.
...
@@ -4066,8 +4066,8 @@ class basic_json
...
@@ -4066,8 +4066,8 @@ class basic_json
@return reference to the element at key @a key
@return reference to the element at key @a key
@throw
std::domain_error if JSON is not an object or null; example:
@throw
type_error.305 if JSON is not an object or null; example: `"cannot
`"cannot
use operator[] with string"`
use operator[] with string"`
@complexity Logarithmic in the size of the container.
@complexity Logarithmic in the size of the container.
...
@@ -4097,7 +4097,7 @@ class basic_json
...
@@ -4097,7 +4097,7 @@ class basic_json
return
m_value
.
object
->
operator
[](
key
);
return
m_value
.
object
->
operator
[](
key
);
}
}
JSON_THROW
(
std
::
domain_error
(
"cannot use operator[] with "
+
type_name
()));
JSON_THROW
(
type_error
(
305
,
"cannot use operator[] with "
+
type_name
()));
}
}
/*!
/*!
...
@@ -4116,7 +4116,7 @@ class basic_json
...
@@ -4116,7 +4116,7 @@ class basic_json
@pre The element with key @a key must exist. **This precondition is
@pre The element with key @a key must exist. **This precondition is
enforced with an assertion.**
enforced with an assertion.**
@throw
std::domain_error
if JSON is not an object; example: `"cannot use
@throw
type_error.305
if JSON is not an object; example: `"cannot use
operator[] with null"`
operator[] with null"`
@complexity Logarithmic in the size of the container.
@complexity Logarithmic in the size of the container.
...
@@ -4140,7 +4140,7 @@ class basic_json
...
@@ -4140,7 +4140,7 @@ class basic_json
return
m_value
.
object
->
find
(
key
)
->
second
;
return
m_value
.
object
->
find
(
key
)
->
second
;
}
}
JSON_THROW
(
std
::
domain_error
(
"cannot use operator[] with "
+
type_name
()));
JSON_THROW
(
type_error
(
305
,
"cannot use operator[] with "
+
type_name
()));
}
}
/*!
/*!
...
...
src/json.hpp.re2c
View file @
aa842b4a
...
@@ -3828,8 +3828,8 @@ class basic_json
...
@@ -3828,8 +3828,8 @@ class basic_json
@return reference to the element at index @a idx
@return reference to the element at index @a idx
@throw
std::domain_error if JSON is not an array or null; example:
@throw
type_error.305 if JSON is not an array or null; example: `"cannot
`"cannot use operator[] with string"`
use operator[] with string"
@complexity Constant if @a idx is in the range of the array. Otherwise
@complexity Constant if @a idx is in the range of the array. Otherwise
linear in `idx - size()`.
linear in `idx - size()`.
...
@@ -3864,7 +3864,7 @@ class basic_json
...
@@ -3864,7 +3864,7 @@ class basic_json
return m_value.array->operator[](idx);
return m_value.array->operator[](idx);
}
}
JSON_THROW(
std::domain_error(
"cannot use operator[] with " + type_name()));
JSON_THROW(
type_error(305,
"cannot use operator[] with " + type_name()));
}
}
/*!
/*!
...
@@ -3876,7 +3876,7 @@ class basic_json
...
@@ -3876,7 +3876,7 @@ class basic_json
@return const reference to the element at index @a idx
@return const reference to the element at index @a idx
@throw
std::domain_error
if JSON is not an array; example: `"cannot use
@throw
type_error.305
if JSON is not an array; example: `"cannot use
operator[] with null"`
operator[] with null"`
@complexity Constant.
@complexity Constant.
...
@@ -3894,7 +3894,7 @@ class basic_json
...
@@ -3894,7 +3894,7 @@ class basic_json
return m_value.array->operator[](idx);
return m_value.array->operator[](idx);
}
}
JSON_THROW(
std::domain_error(
"cannot use operator[] with " + type_name()));
JSON_THROW(
type_error(305,
"cannot use operator[] with " + type_name()));
}
}
/*!
/*!
...
@@ -3910,8 +3910,8 @@ class basic_json
...
@@ -3910,8 +3910,8 @@ class basic_json
@return reference to the element at key @a key
@return reference to the element at key @a key
@throw
std::domain_error if JSON is not an object or null; example:
@throw
type_error.305 if JSON is not an object or null; example: `"cannot
`"cannot
use operator[] with string"`
use operator[] with string"`
@complexity Logarithmic in the size of the container.
@complexity Logarithmic in the size of the container.
...
@@ -3940,7 +3940,7 @@ class basic_json
...
@@ -3940,7 +3940,7 @@ class basic_json
return m_value.object->operator[](key);
return m_value.object->operator[](key);
}
}
JSON_THROW(
std::domain_error(
"cannot use operator[] with " + type_name()));
JSON_THROW(
type_error(305,
"cannot use operator[] with " + type_name()));
}
}
/*!
/*!
...
@@ -3959,7 +3959,7 @@ class basic_json
...
@@ -3959,7 +3959,7 @@ class basic_json
@pre The element with key @a key must exist. **This precondition is
@pre The element with key @a key must exist. **This precondition is
enforced with an assertion.**
enforced with an assertion.**
@throw
std::domain_error
if JSON is not an object; example: `"cannot use
@throw
type_error.305
if JSON is not an object; example: `"cannot use
operator[] with null"`
operator[] with null"`
@complexity Logarithmic in the size of the container.
@complexity Logarithmic in the size of the container.
...
@@ -3982,7 +3982,7 @@ class basic_json
...
@@ -3982,7 +3982,7 @@ class basic_json
return m_value.object->find(key)->second;
return m_value.object->find(key)->second;
}
}
JSON_THROW(
std::domain_error(
"cannot use operator[] with " + type_name()));
JSON_THROW(
type_error(305,
"cannot use operator[] with " + type_name()));
}
}
/*!
/*!
...
@@ -3998,8 +3998,8 @@ class basic_json
...
@@ -3998,8 +3998,8 @@ class basic_json
@return reference to the element at key @a key
@return reference to the element at key @a key
@throw
std::domain_error if JSON is not an object or null; example:
@throw
type_error.305 if JSON is not an object or null; example: `"cannot
`"cannot
use operator[] with string"`
use operator[] with string"`
@complexity Logarithmic in the size of the container.
@complexity Logarithmic in the size of the container.
...
@@ -4066,8 +4066,8 @@ class basic_json
...
@@ -4066,8 +4066,8 @@ class basic_json
@return reference to the element at key @a key
@return reference to the element at key @a key
@throw
std::domain_error if JSON is not an object or null; example:
@throw
type_error.305 if JSON is not an object or null; example: `"cannot
`"cannot
use operator[] with string"`
use operator[] with string"`
@complexity Logarithmic in the size of the container.
@complexity Logarithmic in the size of the container.
...
@@ -4097,7 +4097,7 @@ class basic_json
...
@@ -4097,7 +4097,7 @@ class basic_json
return m_value.object->operator[](key);
return m_value.object->operator[](key);
}
}
JSON_THROW(
std::domain_error(
"cannot use operator[] with " + type_name()));
JSON_THROW(
type_error(305,
"cannot use operator[] with " + type_name()));
}
}
/*!
/*!
...
@@ -4116,7 +4116,7 @@ class basic_json
...
@@ -4116,7 +4116,7 @@ class basic_json
@pre The element with key @a key must exist. **This precondition is
@pre The element with key @a key must exist. **This precondition is
enforced with an assertion.**
enforced with an assertion.**
@throw
std::domain_error
if JSON is not an object; example: `"cannot use
@throw
type_error.305
if JSON is not an object; example: `"cannot use
operator[] with null"`
operator[] with null"`
@complexity Logarithmic in the size of the container.
@complexity Logarithmic in the size of the container.
...
@@ -4140,7 +4140,7 @@ class basic_json
...
@@ -4140,7 +4140,7 @@ class basic_json
return m_value.object->find(key)->second;
return m_value.object->find(key)->second;
}
}
JSON_THROW(
std::domain_error(
"cannot use operator[] with " + type_name()));
JSON_THROW(
type_error(305,
"cannot use operator[] with " + type_name()));
}
}
/*!
/*!
...
...
test/src/unit-element_access1.cpp
View file @
aa842b4a
...
@@ -191,8 +191,8 @@ TEST_CASE("element access 1")
...
@@ -191,8 +191,8 @@ TEST_CASE("element access 1")
json
j_nonarray
(
json
::
value_t
::
null
);
json
j_nonarray
(
json
::
value_t
::
null
);
const
json
j_nonarray_const
(
j_nonarray
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_NOTHROW
(
j_nonarray
[
0
]);
CHECK_NOTHROW
(
j_nonarray
[
0
]);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonarray_const
[
0
],
"cannot use operator[] with null"
);
CHECK_THROWS_WITH
(
j_nonarray_const
[
0
],
"
[json.exception.type_error.305]
cannot use operator[] with null"
);
}
}
SECTION
(
"implicit transformation to properly filled array"
)
SECTION
(
"implicit transformation to properly filled array"
)
...
@@ -207,60 +207,60 @@ TEST_CASE("element access 1")
...
@@ -207,60 +207,60 @@ TEST_CASE("element access 1")
{
{
json
j_nonarray
(
json
::
value_t
::
boolean
);
json
j_nonarray
(
json
::
value_t
::
boolean
);
const
json
j_nonarray_const
(
j_nonarray
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
json
::
type
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonarray
[
0
],
"cannot use operator[] with boolean"
);
CHECK_THROWS_WITH
(
j_nonarray
[
0
],
"
[json.exception.type_error.305]
cannot use operator[] with boolean"
);
CHECK_THROWS_WITH
(
j_nonarray_const
[
0
],
"cannot use operator[] with boolean"
);
CHECK_THROWS_WITH
(
j_nonarray_const
[
0
],
"
[json.exception.type_error.305]
cannot use operator[] with boolean"
);
}
}
SECTION
(
"string"
)
SECTION
(
"string"
)
{
{
json
j_nonarray
(
json
::
value_t
::
string
);
json
j_nonarray
(
json
::
value_t
::
string
);
const
json
j_nonarray_const
(
j_nonarray
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
json
::
type
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonarray
[
0
],
"cannot use operator[] with string"
);
CHECK_THROWS_WITH
(
j_nonarray
[
0
],
"
[json.exception.type_error.305]
cannot use operator[] with string"
);
CHECK_THROWS_WITH
(
j_nonarray_const
[
0
],
"cannot use operator[] with string"
);
CHECK_THROWS_WITH
(
j_nonarray_const
[
0
],
"
[json.exception.type_error.305]
cannot use operator[] with string"
);
}
}
SECTION
(
"object"
)
SECTION
(
"object"
)
{
{
json
j_nonarray
(
json
::
value_t
::
object
);
json
j_nonarray
(
json
::
value_t
::
object
);
const
json
j_nonarray_const
(
j_nonarray
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
json
::
type
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonarray
[
0
],
"cannot use operator[] with object"
);
CHECK_THROWS_WITH
(
j_nonarray
[
0
],
"
[json.exception.type_error.305]
cannot use operator[] with object"
);
CHECK_THROWS_WITH
(
j_nonarray_const
[
0
],
"cannot use operator[] with object"
);
CHECK_THROWS_WITH
(
j_nonarray_const
[
0
],
"
[json.exception.type_error.305]
cannot use operator[] with object"
);
}
}
SECTION
(
"number (integer)"
)
SECTION
(
"number (integer)"
)
{
{
json
j_nonarray
(
json
::
value_t
::
number_integer
);
json
j_nonarray
(
json
::
value_t
::
number_integer
);
const
json
j_nonarray_const
(
j_nonarray
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
json
::
type
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonarray
[
0
],
"cannot use operator[] with number"
);
CHECK_THROWS_WITH
(
j_nonarray
[
0
],
"
[json.exception.type_error.305]
cannot use operator[] with number"
);
CHECK_THROWS_WITH
(
j_nonarray_const
[
0
],
"cannot use operator[] with number"
);
CHECK_THROWS_WITH
(
j_nonarray_const
[
0
],
"
[json.exception.type_error.305]
cannot use operator[] with number"
);
}
}
SECTION
(
"number (unsigned)"
)
SECTION
(
"number (unsigned)"
)
{
{
json
j_nonarray
(
json
::
value_t
::
number_unsigned
);
json
j_nonarray
(
json
::
value_t
::
number_unsigned
);
const
json
j_nonarray_const
(
j_nonarray
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
json
::
type
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonarray
[
0
],
"cannot use operator[] with number"
);
CHECK_THROWS_WITH
(
j_nonarray
[
0
],
"
[json.exception.type_error.305]
cannot use operator[] with number"
);
CHECK_THROWS_WITH
(
j_nonarray_const
[
0
],
"cannot use operator[] with number"
);
CHECK_THROWS_WITH
(
j_nonarray_const
[
0
],
"
[json.exception.type_error.305]
cannot use operator[] with number"
);
}
}
SECTION
(
"number (floating-point)"
)
SECTION
(
"number (floating-point)"
)
{
{
json
j_nonarray
(
json
::
value_t
::
number_float
);
json
j_nonarray
(
json
::
value_t
::
number_float
);
const
json
j_nonarray_const
(
j_nonarray
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
json
::
type
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonarray
[
0
],
"cannot use operator[] with number"
);
CHECK_THROWS_WITH
(
j_nonarray
[
0
],
"
[json.exception.type_error.305]
cannot use operator[] with number"
);
CHECK_THROWS_WITH
(
j_nonarray_const
[
0
],
"cannot use operator[] with number"
);
CHECK_THROWS_WITH
(
j_nonarray_const
[
0
],
"
[json.exception.type_error.305]
cannot use operator[] with number"
);
}
}
}
}
}
}
...
...
test/src/unit-element_access2.cpp
View file @
aa842b4a
This diff is collapsed.
Click to expand it.
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