File: jsonpatch_error.md

package info (click to toggle)
jsoncons 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 17,584 kB
  • sloc: cpp: 136,382; sh: 33; makefile: 5
file content (67 lines) | stat: -rw-r--r-- 1,387 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
### jsoncons::jsonpatch::jsonpatch_error

```cpp
#include <jsoncons_ext/jsonpatch/jsonpatch_error.hpp>
```

<br>

`jsoncons::jsonpatch::jsonpatch_error` defines an exception type for reporting failures in jsonpatch operations.

![jsonpatch_error](./diagrams/jsonpatch_error.png)

#### Constructors

    jsonpatch_error(std::error_code ec)

    jsonpatch_error(const jsonpatch_error& other)

#### Member functions

    const char* what() const noexcept
Returns a message for this exception

#### Inherited from std::system_error

    const std::error_code code() const noexcept
Returns an error code for this exception

### Example

```cpp
#include <jsoncons/json.hpp>
#include <jsoncons_ext/jsonpatch/jsonpatch.hpp>

using jsoncons::json;

int main()
{
    json target = R"(
        { "foo": "bar"}
    )"_json;

    json patch = R"(
        [
            { "op": "add", "path": "/baz", "value": "qux" },
            { "op": "add", "path": "/foo", "value": [ "bar", "baz" ] },
            { "op": "add", "path": "/baz/bat", "value": "qux" } // nonexistent target
        ]
    )"_json;

    try
    {
        jsonpatch::apply_patch(target, patch);
    }
    catch (const jsonpatch::jsonpatch_error& e)
    {
        std::cout << "(1) " << e.what() << '\n';
        std::cout << "(2) " << target << '\n';
    }
}
```

Output:
```
(1) JSON Patch add operation failed
(2) {"foo":"bar"}
```