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
30331fa2
Unverified
Commit
30331fa2
authored
Mar 05, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🔨
added user-defined exception 403
parent
60da36ae
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
42 deletions
+51
-42
src/json.hpp
src/json.hpp
+12
-12
src/json.hpp.re2c
src/json.hpp.re2c
+12
-12
test/src/unit-element_access2.cpp
test/src/unit-element_access2.cpp
+6
-4
test/src/unit-json_patch.cpp
test/src/unit-json_patch.cpp
+18
-12
test/src/unit-json_pointer.cpp
test/src/unit-json_pointer.cpp
+3
-2
No files found.
src/json.hpp
View file @
30331fa2
...
...
@@ -3734,7 +3734,7 @@ class basic_json
@throw type_error.304 if the JSON value is not an object; example:
`"cannot use at() with boolean"`
@throw
std::out_of_range
if the key @a key is is not stored in the object;
@throw
out_of_range.403
if the key @a key is is not stored in the object;
that is, `find(key) == end()`; example: `"key "the fast" not found"`
@complexity Logarithmic in the size of the container.
...
...
@@ -3760,7 +3760,7 @@ class basic_json
JSON_CATCH
(
std
::
out_of_range
&
)
{
// create better exception explanation
JSON_THROW
(
std
::
out_of_range
(
"key '"
+
key
+
"' not found"
));
JSON_THROW
(
out_of_range
(
403
,
"key '"
+
key
+
"' not found"
));
}
}
else
...
...
@@ -3781,7 +3781,7 @@ class basic_json
@throw type_error.304 if the JSON value is not an object; example:
`"cannot use at() with boolean"`
@throw
std::out_of_range
if the key @a key is is not stored in the object;
@throw
out_of_range.403
if the key @a key is is not stored in the object;
that is, `find(key) == end()`; example: `"key "the fast" not found"`
@complexity Logarithmic in the size of the container.
...
...
@@ -3807,7 +3807,7 @@ class basic_json
JSON_CATCH
(
std
::
out_of_range
&
)
{
// create better exception explanation
JSON_THROW
(
std
::
out_of_range
(
"key '"
+
key
+
"' not found"
));
JSON_THROW
(
out_of_range
(
403
,
"key '"
+
key
+
"' not found"
));
}
}
else
...
...
@@ -4154,7 +4154,7 @@ class basic_json
@code {.cpp}
try {
return at(key);
} catch(
std::
out_of_range) {
} catch(out_of_range) {
return default_value;
}
@endcode
...
...
@@ -4233,7 +4233,7 @@ class basic_json
@code {.cpp}
try {
return at(ptr);
} catch(
std::
out_of_range) {
} catch(out_of_range) {
return default_value;
}
@endcode
...
...
@@ -4276,7 +4276,7 @@ class basic_json
{
return
ptr
.
get_checked
(
this
);
}
JSON_CATCH
(
std
::
out_of_range
&
)
JSON_CATCH
(
out_of_range
&
)
{
return
default_value
;
}
...
...
@@ -12746,9 +12746,9 @@ basic_json_parser_74:
any case, the original value is not changed: the patch is applied
to a copy of the value.
@throw
std::out_of_range if a JSON pointer inside the patch could not
be resolved successfully in the current JSON value; example: `"key baz
not
found"`
@throw
out_of_range.403 if a JSON pointer inside the patch could not be
resolved successfully in the current JSON value; example: `"key baz not
found"`
@throw invalid_argument if the JSON patch is malformed (e.g., mandatory
attributes are missing); example: `"operation add must have member path"`
@throw parse_error.104 if the JSON patch does not consist of an array of
...
...
@@ -12888,7 +12888,7 @@ basic_json_parser_74:
}
else
{
JSON_THROW
(
std
::
out_of_range
(
"key '"
+
last_path
+
"' not found"
));
JSON_THROW
(
out_of_range
(
403
,
"key '"
+
last_path
+
"' not found"
));
}
}
else
if
(
parent
.
is_array
())
...
...
@@ -13002,7 +13002,7 @@ basic_json_parser_74:
// the "path" location must exist - use at()
success
=
(
result
.
at
(
ptr
)
==
get_value
(
"test"
,
"value"
,
false
));
}
JSON_CATCH
(
std
::
out_of_range
&
)
JSON_CATCH
(
out_of_range
&
)
{
// ignore out of range errors: success remains false
}
...
...
src/json.hpp.re2c
View file @
30331fa2
...
...
@@ -3734,7 +3734,7 @@ class basic_json
@throw type_error.304 if the JSON value is not an object; example:
`"cannot use at() with boolean"`
@throw
std::out_of_range
if the key @a key is is not stored in the object;
@throw
out_of_range.403
if the key @a key is is not stored in the object;
that is, `find(key) == end()`; example: `"key "the fast" not found"`
@complexity Logarithmic in the size of the container.
...
...
@@ -3760,7 +3760,7 @@ class basic_json
JSON_CATCH (std::out_of_range&)
{
// create better exception explanation
JSON_THROW(
std::out_of_range(
"key '" + key + "' not found"));
JSON_THROW(
out_of_range(403,
"key '" + key + "' not found"));
}
}
else
...
...
@@ -3781,7 +3781,7 @@ class basic_json
@throw type_error.304 if the JSON value is not an object; example:
`"cannot use at() with boolean"`
@throw
std::out_of_range
if the key @a key is is not stored in the object;
@throw
out_of_range.403
if the key @a key is is not stored in the object;
that is, `find(key) == end()`; example: `"key "the fast" not found"`
@complexity Logarithmic in the size of the container.
...
...
@@ -3807,7 +3807,7 @@ class basic_json
JSON_CATCH (std::out_of_range&)
{
// create better exception explanation
JSON_THROW(
std::out_of_range(
"key '" + key + "' not found"));
JSON_THROW(
out_of_range(403,
"key '" + key + "' not found"));
}
}
else
...
...
@@ -4154,7 +4154,7 @@ class basic_json
@code {.cpp}
try {
return at(key);
} catch(
std::
out_of_range) {
} catch(out_of_range) {
return default_value;
}
@endcode
...
...
@@ -4233,7 +4233,7 @@ class basic_json
@code {.cpp}
try {
return at(ptr);
} catch(
std::
out_of_range) {
} catch(out_of_range) {
return default_value;
}
@endcode
...
...
@@ -4276,7 +4276,7 @@ class basic_json
{
return ptr.get_checked(this);
}
JSON_CATCH (
std::
out_of_range&)
JSON_CATCH (out_of_range&)
{
return default_value;
}
...
...
@@ -11779,9 +11779,9 @@ class basic_json
any case, the original value is not changed: the patch is applied
to a copy of the value.
@throw
std::out_of_range if a JSON pointer inside the patch could not
be resolved successfully in the current JSON value; example: `"key baz
not
found"`
@throw
out_of_range.403 if a JSON pointer inside the patch could not be
resolved successfully in the current JSON value; example: `"key baz not
found"`
@throw invalid_argument if the JSON patch is malformed (e.g., mandatory
attributes are missing); example: `"operation add must have member path"`
@throw parse_error.104 if the JSON patch does not consist of an array of
...
...
@@ -11921,7 +11921,7 @@ class basic_json
}
else
{
JSON_THROW(
std::out_of_range(
"key '" + last_path + "' not found"));
JSON_THROW(
out_of_range(403,
"key '" + last_path + "' not found"));
}
}
else if (parent.is_array())
...
...
@@ -12035,7 +12035,7 @@ class basic_json
// the "path" location must exist - use at()
success = (result.at(ptr) == get_value("test", "value", false));
}
JSON_CATCH (
std::
out_of_range&)
JSON_CATCH (out_of_range&)
{
// ignore out of range errors: success remains false
}
...
...
test/src/unit-element_access2.cpp
View file @
30331fa2
...
...
@@ -63,10 +63,12 @@ TEST_CASE("element access 2")
SECTION
(
"access outside bounds"
)
{
CHECK_THROWS_AS
(
j
.
at
(
"foo"
),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j_const
.
at
(
"foo"
),
std
::
out_of_range
);
CHECK_THROWS_WITH
(
j
.
at
(
"foo"
),
"key 'foo' not found"
);
CHECK_THROWS_WITH
(
j_const
.
at
(
"foo"
),
"key 'foo' not found"
);
CHECK_THROWS_AS
(
j
.
at
(
"foo"
),
json
::
out_of_range
);
CHECK_THROWS_AS
(
j_const
.
at
(
"foo"
),
json
::
out_of_range
);
CHECK_THROWS_WITH
(
j
.
at
(
"foo"
),
"[json.exception.out_of_range.403] key 'foo' not found"
);
CHECK_THROWS_WITH
(
j_const
.
at
(
"foo"
),
"[json.exception.out_of_range.403] key 'foo' not found"
);
}
SECTION
(
"access on non-object type"
)
...
...
test/src/unit-json_patch.cpp
View file @
30331fa2
...
...
@@ -75,8 +75,9 @@ TEST_CASE("JSON patch")
json
doc2
=
R"({ "q": { "bar": 2 } })"
_json
;
// because "a" does not exist.
CHECK_THROWS_AS
(
doc2
.
patch
(
patch
),
std
::
out_of_range
);
CHECK_THROWS_WITH
(
doc2
.
patch
(
patch
),
"key 'a' not found"
);
CHECK_THROWS_AS
(
doc2
.
patch
(
patch
),
json
::
out_of_range
);
CHECK_THROWS_WITH
(
doc2
.
patch
(
patch
),
"[json.exception.out_of_range.403] key 'a' not found"
);
}
SECTION
(
"4.2 remove"
)
...
...
@@ -420,8 +421,9 @@ TEST_CASE("JSON patch")
// references neither the root of the document, nor a member of
// an existing object, nor a member of an existing array.
CHECK_THROWS_AS
(
doc
.
patch
(
patch
),
std
::
out_of_range
);
CHECK_THROWS_WITH
(
doc
.
patch
(
patch
),
"key 'baz' not found"
);
CHECK_THROWS_AS
(
doc
.
patch
(
patch
),
json
::
out_of_range
);
CHECK_THROWS_WITH
(
doc
.
patch
(
patch
),
"[json.exception.out_of_range.403] key 'baz' not found"
);
}
// A.13. Invalid JSON Patch Document
...
...
@@ -780,8 +782,9 @@ TEST_CASE("JSON patch")
{
json
j
=
{{
"foo"
,
1
},
{
"bar"
,
2
}};
json
patch
=
{{{
"op"
,
"remove"
},
{
"path"
,
"/baz"
}}};
CHECK_THROWS_AS
(
j
.
patch
(
patch
),
std
::
out_of_range
);
CHECK_THROWS_WITH
(
j
.
patch
(
patch
),
"key 'baz' not found"
);
CHECK_THROWS_AS
(
j
.
patch
(
patch
),
json
::
out_of_range
);
CHECK_THROWS_WITH
(
j
.
patch
(
patch
),
"[json.exception.out_of_range.403] key 'baz' not found"
);
}
SECTION
(
"root element as target location"
)
...
...
@@ -835,8 +838,9 @@ TEST_CASE("JSON patch")
{
json
j
=
{{
"foo"
,
1
},
{
"bar"
,
2
}};
json
patch
=
{{{
"op"
,
"replace"
},
{
"path"
,
"/baz"
},
{
"value"
,
3
}}};
CHECK_THROWS_AS
(
j
.
patch
(
patch
),
std
::
out_of_range
);
CHECK_THROWS_WITH
(
j
.
patch
(
patch
),
"key 'baz' not found"
);
CHECK_THROWS_AS
(
j
.
patch
(
patch
),
json
::
out_of_range
);
CHECK_THROWS_WITH
(
j
.
patch
(
patch
),
"[json.exception.out_of_range.403] key 'baz' not found"
);
}
}
...
...
@@ -891,8 +895,9 @@ TEST_CASE("JSON patch")
{
json
j
=
{{
"foo"
,
1
},
{
"bar"
,
2
}};
json
patch
=
{{{
"op"
,
"move"
},
{
"path"
,
"/baz"
},
{
"from"
,
"/baz"
}}};
CHECK_THROWS_AS
(
j
.
patch
(
patch
),
std
::
out_of_range
);
CHECK_THROWS_WITH
(
j
.
patch
(
patch
),
"key 'baz' not found"
);
CHECK_THROWS_AS
(
j
.
patch
(
patch
),
json
::
out_of_range
);
CHECK_THROWS_WITH
(
j
.
patch
(
patch
),
"[json.exception.out_of_range.403] key 'baz' not found"
);
}
}
...
...
@@ -947,8 +952,9 @@ TEST_CASE("JSON patch")
{
json
j
=
{{
"foo"
,
1
},
{
"bar"
,
2
}};
json
patch
=
{{{
"op"
,
"copy"
},
{
"path"
,
"/fob"
},
{
"from"
,
"/baz"
}}};
CHECK_THROWS_AS
(
j
.
patch
(
patch
),
std
::
out_of_range
);
CHECK_THROWS_WITH
(
j
.
patch
(
patch
),
"key 'baz' not found"
);
CHECK_THROWS_AS
(
j
.
patch
(
patch
),
json
::
out_of_range
);
CHECK_THROWS_WITH
(
j
.
patch
(
patch
),
"[json.exception.out_of_range.403] key 'baz' not found"
);
}
}
...
...
test/src/unit-json_pointer.cpp
View file @
30331fa2
...
...
@@ -185,8 +185,9 @@ TEST_CASE("JSON pointers")
CHECK
(
j
[
json
::
json_pointer
(
"/m~0n"
)]
==
j
[
"m~n"
]);
// unescaped access
CHECK_THROWS_AS
(
j
.
at
(
json
::
json_pointer
(
"/a/b"
)),
std
::
out_of_range
);
CHECK_THROWS_WITH
(
j
.
at
(
json
::
json_pointer
(
"/a/b"
)),
"key 'a' not found"
);
CHECK_THROWS_AS
(
j
.
at
(
json
::
json_pointer
(
"/a/b"
)),
json
::
out_of_range
);
CHECK_THROWS_WITH
(
j
.
at
(
json
::
json_pointer
(
"/a/b"
)),
"[json.exception.out_of_range.403] key 'a' not found"
);
// unresolved access
const
json
j_primitive
=
1
;
...
...
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