1 # <small>nlohmann::basic_json::</small>type_error
4 class type_error : public exception;
7 This exception is thrown in case of a type error; that is, a library function is executed on a JSON value whose type
8 does not match the expected semantics.
10 Exceptions have ids 3xx (see [list of type errors](../../home/exceptions.md#type-errors)).
13 std::exception <|-- basic_json::exception
14 basic_json::exception <|-- basic_json::parse_error
15 basic_json::exception <|-- basic_json::invalid_iterator
16 basic_json::exception <|-- basic_json::type_error
17 basic_json::exception <|-- basic_json::out_of_range
18 basic_json::exception <|-- basic_json::other_error
20 interface std::exception {}
22 class basic_json::exception {
24 + const char* what() const
27 class basic_json::parse_error {
28 + const std::size_t byte
31 class basic_json::type_error #FFFF00 {}
36 - **what** - returns explanatory string
40 - **id** - the id of the exception
46 The following code shows how a `type_error` exception can be caught.
49 --8<-- "examples/type_error.cpp"
55 --8<-- "examples/type_error.output"
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
68 - Since version 3.0.0.