1# <small>nlohmann::basic_json::</small>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## Notes 48 49To have nothrow-copy-constructible exceptions, we internally use `std::runtime_error` which can cope with 50arbitrary-length error messages. Intermediate strings are built with static functions and then passed to the actual 51constructor. 52 53## Examples 54 55??? example 56 57 The following code shows how arbitrary library exceptions can be caught. 58 59 ```cpp 60 --8<-- "examples/exception.cpp" 61 ``` 62 63 Output: 64 65 ```json 66 --8<-- "examples/exception.output" 67 ``` 68 69## See also 70 71[List of exceptions](127.0.0.1:8000/home/exceptions/) 72 73## Version history 74 75- Since version 3.0.0. 76