1# <small>nlohmann::basic_json::</small>parse_error 2 3```cpp 4class parse_error : public exception; 5``` 6 7This exception is thrown by the library when a parse error occurs. Parse errors can occur during the deserialization of 8JSON text, BSON, CBOR, MessagePack, UBJSON, as well as when using JSON Patch. 9 10Member `byte` holds the byte index of the last read character in the input file (see note below). 11 12Exceptions have ids 1xx (see [list of parse errors](../../home/exceptions.md#parse-errors)). 13 14```plantuml 15std::exception <|-- basic_json::exception 16basic_json::exception <|-- basic_json::parse_error 17basic_json::exception <|-- basic_json::invalid_iterator 18basic_json::exception <|-- basic_json::type_error 19basic_json::exception <|-- basic_json::out_of_range 20basic_json::exception <|-- basic_json::other_error 21 22interface std::exception {} 23 24class basic_json::exception { 25 + const int id 26 + const char* what() const 27} 28 29class basic_json::parse_error #FFFF00 { 30 + const std::size_t byte 31} 32``` 33 34## Member functions 35 36- **what** - returns explanatory string 37 38## Member variables 39 40- **id** - the id of the exception 41- **byte** - byte index of the parse error 42 43## Notes 44 45For an input with $n$ bytes, 1 is the index of the first character and $n+1$ is the index of the terminating null byte 46or the end of file. This also holds true when reading a byte vector for binary formats. 47 48## Examples 49 50??? example 51 52 The following code shows how a `parse_error` exception can be caught. 53 54 ```cpp 55 --8<-- "examples/parse_error.cpp" 56 ``` 57 58 Output: 59 60 ```json 61 --8<-- "examples/parse_error.output" 62 ``` 63 64## See also 65 66- [List of parse errors](../../home/exceptions.md#parse-errors) 67- [`invalid_iterator`](invalid_iterator.md) for exceptions indicating errors with iterators 68- [`type_error`](type_error.md) for exceptions indicating executing a member function with a wrong type 69- [`out_of_range`](out_of_range.md) for exceptions indicating access out of the defined range 70- [`other_error`](other_error.md) for exceptions indicating other library errors 71 72## Version history 73 74- Since version 3.0.0. 75