• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# <small>nlohmann::basic_json::</small>type_error
2
3```cpp
4class type_error : public exception;
5```
6
7This exception is thrown in case of a type error; that is, a library function is executed on a JSON value whose type
8does not match the expected semantics.
9
10Exceptions have ids 3xx (see [list of type errors](../../home/exceptions.md#type-errors)).
11
12```plantuml
13std::exception <|-- basic_json::exception
14basic_json::exception <|-- basic_json::parse_error
15basic_json::exception <|-- basic_json::invalid_iterator
16basic_json::exception <|-- basic_json::type_error
17basic_json::exception <|-- basic_json::out_of_range
18basic_json::exception <|-- basic_json::other_error
19
20interface std::exception {}
21
22class basic_json::exception {
23    + const int id
24    + const char* what() const
25}
26
27class basic_json::parse_error {
28    + const std::size_t byte
29}
30
31class basic_json::type_error #FFFF00 {}
32```
33
34## Member functions
35
36- **what** - returns explanatory string
37
38## Member variables
39
40- **id** - the id of the exception
41
42## Examples
43
44??? example
45
46    The following code shows how a `type_error` exception can be caught.
47
48    ```cpp
49    --8<-- "examples/type_error.cpp"
50    ```
51
52    Output:
53
54    ```json
55    --8<-- "examples/type_error.output"
56    ```
57
58## See also
59
60- [List of type errors](../../home/exceptions.md#type-errors)
61- [`parse_error`](parse_error.md) for exceptions indicating a parse error
62- [`invalid_iterator`](invalid_iterator.md) for exceptions indicating errors with iterators
63- [`out_of_range`](out_of_range.md) for exceptions indicating access out of the defined range
64- [`other_error`](other_error.md) for exceptions indicating other library errors
65
66## Version history
67
68- Since version 3.0.0.
69