• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# basic_json::exception
2
3```cpp
4class exception : public std::exception;
5```
6
7This class is an extension of [`std::exception`](https://en.cppreference.com/w/cpp/error/exception) objects with a
8member `id` for exception ids. It is used as the base class for all exceptions thrown by the `basic_json` class. This
9class can hence be used as "wildcard" to catch exceptions, see example below.
10
11```plantuml
12std::exception <|-- basic_json::exception
13basic_json::exception <|-- basic_json::parse_error
14basic_json::exception <|-- basic_json::invalid_iterator
15basic_json::exception <|-- basic_json::type_error
16basic_json::exception <|-- basic_json::out_of_range
17basic_json::exception <|-- basic_json::other_error
18
19interface std::exception {}
20
21class basic_json::exception #FFFF00 {
22    + const int id
23    + const char* what() const
24}
25
26class basic_json::parse_error {
27    + const std::size_t byte
28}
29```
30
31Subclasses:
32
33- [`parse_error`](parse_error.md) for exceptions indicating a parse error
34- [`invalid_iterator`](invalid_iterator.md) for exceptions indicating errors with iterators
35- [`type_error`](type_error.md) for exceptions indicating executing a member function with a wrong type
36- [`out_of_range`](out_of_range.md) for exceptions indicating access out of the defined range
37- [`other_error`](other_error.md) for exceptions indicating other library errors
38
39## Member functions
40
41- **what** - returns explanatory string
42
43## Member variables
44
45- **id** - the id of the exception
46
47## Example
48
49??? example
50
51    The following code shows how arbitrary library exceptions can be caught.
52
53    ```cpp
54    --8<-- "examples/exception.cpp"
55    ```
56
57    Output:
58
59    ```json
60    --8<-- "examples/exception.output"
61    ```
62
63## Version history
64
65- Since version 3.0.0.
66