1# Exceptions 2 3## Overview 4 5### Base type 6 7All exceptions inherit from class `json::exception` (which in turn inherits from `std::exception`). It is used as the base class for all exceptions thrown by the `basic_json` class. This class can hence be used as "wildcard" to catch exceptions. 8 9```plantuml 10std::exception <|-- json::exception 11json::exception <|-- json::parse_error 12json::exception <|-- json::invalid_iterator 13json::exception <|-- json::type_error 14json::exception <|-- json::out_of_range 15json::exception <|-- json::other_error 16 17interface std::exception {} 18 19class json::exception { 20 + const int id 21 + const char* what() const 22} 23 24class json::parse_error { 25 + const std::size_t byte 26} 27``` 28 29### Switch off exceptions 30 31Exceptions are used widely within the library. They can, however, be switched off with either using the compiler flag `-fno-exceptions` or by defining the symbol `JSON_NOEXCEPTION`. In this case, exceptions are replaced by `abort()` calls. You can further control this behavior by defining `JSON_THROW_USER` (overriding `#!cpp throw`), `JSON_TRY_USER` (overriding `#!cpp try`), and `JSON_CATCH_USER` (overriding `#!cpp catch`). 32 33Note that `JSON_THROW_USER` should leave the current scope (e.g., by throwing or aborting), as continuing after it may yield undefined behavior. 34 35??? example 36 37 The code below switches off exceptions and creates a log entry with a detailed error message in case of errors. 38 39 ```cpp 40 #include <iostream> 41 42 #define JSON_TRY_USER if(true) 43 #define JSON_CATCH_USER(exception) if(false) 44 #define JSON_THROW_USER(exception) \ 45 {std::clog << "Error in " << __FILE__ << ":" << __LINE__ \ 46 << " (function " << __FUNCTION__ << ") - " \ 47 << (exception).what() << std::endl; \ 48 std::abort();} 49 50 #include <nlohmann/json.hpp> 51 ``` 52 53Note the explanatory [`what()`](https://en.cppreference.com/w/cpp/error/exception/what) string of exceptions is not available for MSVC if exceptions are disabled, see [#2824](https://github.com/nlohmann/json/discussions/2824). 54 55### Extended diagnostic messages 56 57Exceptions in the library are thrown in the local context of the JSON value they are detected. This makes detailed diagnostics messages, and hence debugging, difficult. 58 59??? example 60 61 ```cpp 62 --8<-- "examples/diagnostics_standard.cpp" 63 ``` 64 65 Output: 66 67 ``` 68 --8<-- "examples/diagnostics_standard.output" 69 ``` 70 71 This exception can be hard to debug if storing the value `#!c "12"` and accessing it is further apart. 72 73To create better diagnostics messages, each JSON value needs a pointer to its parent value such that a global context (i.e., a path from the root value to the value that lead to the exception) can be created. That global context is provided as [JSON Pointer](../features/json_pointer.md). 74 75As this global context comes at the price of storing one additional pointer per JSON value and runtime overhead to maintain the parent relation, extended diagnostics are disabled by default. They can, however, be enabled by defining the preprocessor symbol [`JSON_DIAGNOSTICS`](../features/macros.md#json_diagnostics) to `1` before including `json.hpp`. 76 77??? example 78 79 ```cpp 80 --8<-- "examples/diagnostics_extended.cpp" 81 ``` 82 83 Output: 84 85 ``` 86 --8<-- "examples/diagnostics_extended.output" 87 ``` 88 89 Now the exception message contains a JSON Pointer `/address/housenumber` that indicates which value has the wrong type. 90 91 92## Parse errors 93 94This exception is thrown by the library when a parse error occurs. Parse errors 95can occur during the deserialization of JSON text, CBOR, MessagePack, as well 96as when using JSON Patch. 97 98Exceptions have ids 1xx. 99 100!!! info "Byte index" 101 102 Member `byte` holds the byte index of the last read character in the input 103 file. 104 105 For an input with n bytes, 1 is the index of the first character and n+1 106 is the index of the terminating null byte or the end of file. This also 107 holds true when reading a byte vector (CBOR or MessagePack). 108 109??? example 110 111 The following code shows how a `parse_error` exception can be caught. 112 113 ```cpp 114 --8<-- "examples/parse_error.cpp" 115 ``` 116 117 Output: 118 119 ``` 120 --8<-- "examples/parse_error.output" 121 ``` 122 123 124### json.exception.parse_error.101 125 126This error indicates a syntax error while deserializing a JSON text. The error message describes that an unexpected token (character) was encountered, and the member `byte` indicates the error position. 127 128!!! failure "Example message" 129 130 Input ended prematurely: 131 132 ``` 133 [json.exception.parse_error.101] parse error at 2: unexpected end of input; expected string literal 134 ``` 135 136 No input: 137 138 ``` 139 [json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal 140 ``` 141 142 Control character was not escaped: 143 144 ``` 145 [json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0009 (HT) must be escaped to \u0009 or \\; last read: '"<U+0009>'" 146 ``` 147 148 String was not closed: 149 150 ``` 151 [json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: missing closing quote; last read: '"' 152 ``` 153 154 Invalid number format: 155 156 ``` 157 [json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1E' 158 ``` 159 160 `\u` was not be followed by four hex digits: 161 162 ``` 163 [json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid string: '\u' must be followed by 4 hex digits; last read: '"\u01"' 164 ``` 165 166 Invalid UTF-8 surrogate pair: 167 168 ``` 169 [json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF; last read: '"\uD7FF\uDC00'" 170 ``` 171 172 Invalid UTF-8 byte: 173 174 ``` 175 [json.exception.parse_error.101] parse error at line 3, column 24: syntax error while parsing value - invalid string: ill-formed UTF-8 byte; last read: '"vous \352t' 176 ``` 177 178!!! tip 179 180 - Make sure the input is correctly read. Try to write the input to standard output to check if, for instance, the input file was successfully openened. 181 - Paste the input to a JSON validator like <http://jsonlint.com> or a tool like [jq](https://stedolan.github.io/jq/). 182 183### json.exception.parse_error.102 184 185JSON uses the `\uxxxx` format to describe Unicode characters. Code points above above 0xFFFF are split into two `\uxxxx` entries ("surrogate pairs"). This error indicates that the surrogate pair is incomplete or contains an invalid code point. 186 187!!! failure "Example message" 188 189 ``` 190 parse error at 14: missing or wrong low surrogate 191 ``` 192 193!!! note 194 195 This exception is not used any more. Instead [json.exception.parse_error.101](#jsonexceptionparse_error101) with a more detailed description is used. 196 197### json.exception.parse_error.103 198 199Unicode supports code points up to 0x10FFFF. Code points above 0x10FFFF are invalid. 200 201!!! failure "Example message" 202 203 ``` 204 parse error: code points above 0x10FFFF are invalid 205 ``` 206 207!!! note 208 209 This exception is not used any more. Instead [json.exception.parse_error.101](#jsonexceptionparse_error101) with a more detailed description is used. 210 211### json.exception.parse_error.104 212 213[RFC 6902](https://tools.ietf.org/html/rfc6902) requires a JSON Patch document to be a JSON document that represents an array of objects. 214 215!!! failure "Example message" 216 217 ``` 218 [json.exception.parse_error.104] parse error: JSON patch must be an array of objects 219 ``` 220 221### json.exception.parse_error.105 222 223An operation of a JSON Patch document must contain exactly one "op" member, whose value indicates the operation to perform. Its value must be one of "add", "remove", "replace", "move", "copy", or "test"; other values are errors. 224 225!!! failure "Example message" 226 227 ``` 228 [json.exception.parse_error.105] parse error: operation 'add' must have member 'value' 229 ``` 230 ``` 231 [json.exception.parse_error.105] parse error: operation 'copy' must have string member 'from' 232 ``` 233 ``` 234 [json.exception.parse_error.105] parse error: operation value 'foo' is invalid 235 ``` 236 237### json.exception.parse_error.106 238 239An array index in a JSON Pointer ([RFC 6901](https://tools.ietf.org/html/rfc6901)) may be `0` or any number without a leading `0`. 240 241!!! failure "Example message" 242 243 ``` 244 [json.exception.parse_error.106] parse error: array index '01' must not begin with '0' 245 ``` 246 247### json.exception.parse_error.107 248 249A JSON Pointer must be a Unicode string containing a sequence of zero or more reference tokens, each prefixed by a `/` character. 250 251!!! failure "Example message" 252 253 ``` 254 [json.exception.parse_error.107] parse error at byte 1: JSON pointer must be empty or begin with '/' - was: 'foo' 255 ``` 256 257### json.exception.parse_error.108 258 259In a JSON Pointer, only `~0` and `~1` are valid escape sequences. 260 261!!! failure "Example message" 262 263 ``` 264 [json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1' 265 ``` 266 267### json.exception.parse_error.109 268 269A JSON Pointer array index must be a number. 270 271!!! failure "Example message" 272 273 ``` 274 [json.exception.parse_error.109] parse error: array index 'one' is not a number 275 ``` 276 ``` 277 [json.exception.parse_error.109] parse error: array index '+1' is not a number 278 ``` 279 280### json.exception.parse_error.110 281 282When parsing CBOR or MessagePack, the byte vector ends before the complete value has been read. 283 284!!! failure "Example message" 285 286 ``` 287 [json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR string: unexpected end of input 288 ``` 289 ``` 290 [json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON value: expected end of input; last byte: 0x5A 291 ``` 292 293### json.exception.parse_error.112 294 295Not all types of CBOR or MessagePack are supported. This exception occurs if an unsupported byte was read. 296 297!!! failure "Example message" 298 299 ``` 300 [json.exception.parse_error.112] parse error at byte 1: syntax error while parsing CBOR value: invalid byte: 0x1C 301 ``` 302 303### json.exception.parse_error.113 304 305While parsing a map key, a value that is not a string has been read. 306 307!!! failure "Example message" 308 309 ``` 310 [json.exception.parse_error.113] parse error at byte 2: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0xFF 311 ``` 312 ``` 313 [json.exception.parse_error.113] parse error at byte 2: syntax error while parsing MessagePack string: expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0xFF 314 ``` 315 ``` 316 [json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON char: byte after 'C' must be in range 0x00..0x7F; last byte: 0x82 317 ``` 318 319### json.exception.parse_error.114 320 321The parsing of the corresponding BSON record type is not implemented (yet). 322 323!!! failure "Example message" 324 325 ``` 326 [json.exception.parse_error.114] parse error at byte 5: Unsupported BSON record type 0xFF 327 ``` 328 329### json.exception.parse_error.115 330 331A UBJSON high-precision number could not be parsed. 332 333!!! failure "Example message" 334 335 ``` 336 [json.exception.parse_error.115] parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1A 337 ``` 338 339## Iterator errors 340 341This exception is thrown if iterators passed to a library function do not match 342the expected semantics. 343 344Exceptions have ids 2xx. 345 346??? example 347 348 The following code shows how an `invalid_iterator` exception can be caught. 349 350 ```cpp 351 --8<-- "examples/invalid_iterator.cpp" 352 ``` 353 354 Output: 355 356 ``` 357 --8<-- "examples/invalid_iterator.output" 358 ``` 359 360### json.exception.invalid_iterator.201 361 362The iterators passed to constructor `basic_json(InputIT first, InputIT last)` are not compatible, meaning they do not belong to the same container. Therefore, the range (`first`, `last`) is invalid. 363 364!!! failure "Example message" 365 366 ``` 367 [json.exception.invalid_iterator.201] iterators are not compatible 368 ``` 369 370### json.exception.invalid_iterator.202 371 372In an [erase](../api/basic_json/erase.md) or insert function, the passed iterator `pos` does not belong to the JSON value for which the function was called. It hence does not define a valid position for the deletion/insertion. 373 374!!! failure "Example message" 375 376 ``` 377 [json.exception.invalid_iterator.202] iterator does not fit current value 378 ``` 379 ``` 380 [json.exception.invalid_iterator.202] iterators first and last must point to objects 381 ``` 382 383### json.exception.invalid_iterator.203 384 385Either iterator passed to function [`erase(IteratorType first, IteratorType last`)](../api/basic_json/erase.md) does not belong to the JSON value from which values shall be erased. It hence does not define a valid range to delete values from. 386 387!!! failure "Example message" 388 389 ``` 390 [json.exception.invalid_iterator.203] iterators do not fit current value 391 ``` 392 393### json.exception.invalid_iterator.204 394 395When an iterator range for a primitive type (number, boolean, or string) is passed to a constructor or an [erase](../api/basic_json/erase.md) function, this range has to be exactly (`begin(),` `end()),` because this is the only way the single stored value is expressed. All other ranges are invalid. 396 397!!! failure "Example message" 398 399 ``` 400 [json.exception.invalid_iterator.204] iterators out of range 401 ``` 402 403### json.exception.invalid_iterator.205 404 405When an iterator for a primitive type (number, boolean, or string) is passed to an [erase](../api/basic_json/erase.md) function, the iterator has to be the `begin()` iterator, because it is the only way to address the stored value. All other iterators are invalid. 406 407!!! failure "Example message" 408 409 ``` 410 [json.exception.invalid_iterator.205] iterator out of range 411 ``` 412 413### json.exception.invalid_iterator.206 414 415The iterators passed to constructor `basic_json(InputIT first, InputIT last)` belong to a JSON null value and hence to not define a valid range. 416 417!!! failure "Example message" 418 419 ``` 420 [json.exception.invalid_iterator.206] cannot construct with iterators from null 421 ``` 422 423### json.exception.invalid_iterator.207 424 425The `key()` member function can only be used on iterators belonging to a JSON object, because other types do not have a concept of a key. 426 427!!! failure "Example message" 428 429 ``` 430 [json.exception.invalid_iterator.207] cannot use key() for non-object iterators 431 ``` 432 433 434### json.exception.invalid_iterator.208 435 436The `operator[]` to specify a concrete offset cannot be used on iterators belonging to a JSON object, because JSON objects are unordered. 437 438!!! failure "Example message" 439 440 ``` 441 [json.exception.invalid_iterator.208] cannot use operator[] for object iterators 442 ``` 443 444### json.exception.invalid_iterator.209 445 446The offset operators (`+`, `-`, `+=`, `-=`) cannot be used on iterators belonging to a JSON object, because JSON objects are unordered. 447 448!!! failure "Example message" 449 450 ``` 451 [json.exception.invalid_iterator.209] cannot use offsets with object iterators 452 ``` 453 454### json.exception.invalid_iterator.210 455 456The iterator range passed to the insert function are not compatible, meaning they do not belong to the same container. Therefore, the range (`first`, `last`) is invalid. 457 458!!! failure "Example message" 459 460 ``` 461 [json.exception.invalid_iterator.210] iterators do not fit 462 ``` 463 464### json.exception.invalid_iterator.211 465 466The iterator range passed to the insert function must not be a subrange of the container to insert to. 467 468!!! failure "Example message" 469 470 ``` 471 [json.exception.invalid_iterator.211] passed iterators may not belong to container 472 ``` 473 474### json.exception.invalid_iterator.212 475 476When two iterators are compared, they must belong to the same container. 477 478!!! failure "Example message" 479 480 ``` 481 [json.exception.invalid_iterator.212] cannot compare iterators of different containers 482 ``` 483 484### json.exception.invalid_iterator.213 485 486The order of object iterators cannot be compared, because JSON objects are unordered. 487 488!!! failure "Example message" 489 490 ``` 491 [json.exception.invalid_iterator.213] cannot compare order of object iterators 492 ``` 493 494### json.exception.invalid_iterator.214 495 496Cannot get value for iterator: Either the iterator belongs to a null value or it is an iterator to a primitive type (number, boolean, or string), but the iterator is different to `begin()`. 497 498!!! failure "Example message" 499 500 ``` 501 [json.exception.invalid_iterator.214] cannot get value 502 ``` 503 504## Type errors 505 506This exception is thrown in case of a type error; that is, a library function is executed on a JSON value whose type does not match the expected semantics. 507 508Exceptions have ids 3xx. 509 510??? example 511 512 The following code shows how a `type_error` exception can be caught. 513 514 ```cpp 515 --8<-- "examples/type_error.cpp" 516 ``` 517 518 Output: 519 520 ``` 521 --8<-- "examples/type_error.output" 522 ``` 523 524### json.exception.type_error.301 525 526To create an object from an initializer list, the initializer list must consist only of a list of pairs whose first element is a string. When this constraint is violated, an array is created instead. 527 528!!! failure "Example message" 529 530 ``` 531 [json.exception.type_error.301] cannot create object from initializer list 532 ``` 533 534### json.exception.type_error.302 535 536During implicit or explicit value conversion, the JSON type must be compatible to the target type. For instance, a JSON string can only be converted into string types, but not into numbers or boolean types. 537 538!!! failure "Example message" 539 540 ``` 541 [json.exception.type_error.302] type must be object, but is null 542 ``` 543 ``` 544 [json.exception.type_error.302] type must be string, but is object 545 ``` 546 547### json.exception.type_error.303 548 549To retrieve a reference to a value stored in a `basic_json` object with `get_ref`, the type of the reference must match the value type. For instance, for a JSON array, the `ReferenceType` must be `array_t &`. 550 551!!! failure "Example message" 552 553 ``` 554 [json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object 555 ``` 556 ``` 557 [json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number" 558 ``` 559 560### json.exception.type_error.304 561 562The `at()` member functions can only be executed for certain JSON types. 563 564!!! failure "Example message" 565 566 ``` 567 [json.exception.type_error.304] cannot use at() with string 568 ``` 569 ``` 570 [json.exception.type_error.304] cannot use at() with number 571 ``` 572 573### json.exception.type_error.305 574 575The `operator[]` member functions can only be executed for certain JSON types. 576 577!!! failure "Example message" 578 579 ``` 580 [json.exception.type_error.305] cannot use operator[] with a string argument with array 581 ``` 582 ``` 583 [json.exception.type_error.305] cannot use operator[] with a numeric argument with object 584 ``` 585 586### json.exception.type_error.306 587 588The `value()` member functions can only be executed for certain JSON types. 589 590!!! failure "Example message" 591 592 ``` 593 [json.exception.type_error.306] cannot use value() with number 594 ``` 595 596### json.exception.type_error.307 597 598The [`erase()`](../api/basic_json/erase.md) member functions can only be executed for certain JSON types. 599 600!!! failure "Example message" 601 602 ``` 603 [json.exception.type_error.307] cannot use erase() with string 604 ``` 605 606### json.exception.type_error.308 607 608The `push_back()` and `operator+=` member functions can only be executed for certain JSON types. 609 610!!! failure "Example message" 611 612 ``` 613 [json.exception.type_error.308] cannot use push_back() with string 614 ``` 615 616### json.exception.type_error.309 617 618The `insert()` member functions can only be executed for certain JSON types. 619 620!!! failure "Example message" 621 622 ``` 623 [json.exception.type_error.309] cannot use insert() with array 624 ``` 625 ``` 626 [json.exception.type_error.309] cannot use insert() with number 627 ``` 628 629### json.exception.type_error.310 630 631The `swap()` member functions can only be executed for certain JSON types. 632 633!!! failure "Example message" 634 635 ``` 636 [json.exception.type_error.310] cannot use swap() with number 637 ``` 638 639### json.exception.type_error.311 640 641The `emplace()` and `emplace_back()` member functions can only be executed for certain JSON types. 642 643!!! failure "Example message" 644 645 ``` 646 [json.exception.type_error.311] cannot use emplace() with number 647 ``` 648 ``` 649 [json.exception.type_error.311] cannot use emplace_back() with number 650 ``` 651 652### json.exception.type_error.312 653 654The `update()` member functions can only be executed for certain JSON types. 655 656!!! failure "Example message" 657 658 ``` 659 [json.exception.type_error.312] cannot use update() with array 660 ``` 661 662### json.exception.type_error.313 663 664The `unflatten` function converts an object whose keys are JSON Pointers back into an arbitrary nested JSON value. The JSON Pointers must not overlap, because then the resulting value would not be well defined. 665 666!!! failure "Example message" 667 668 ``` 669 [json.exception.type_error.313] invalid value to unflatten 670 ``` 671 672### json.exception.type_error.314 673 674The `unflatten` function only works for an object whose keys are JSON Pointers. 675 676!!! failure "Example message" 677 678 Calling `unflatten()` on an array `#!json [1,2,3]`: 679 680 ``` 681 [json.exception.type_error.314] only objects can be unflattened 682 ``` 683 684### json.exception.type_error.315 685 686The `unflatten()` function only works for an object whose keys are JSON Pointers and whose values are primitive. 687 688!!! failure "Example message" 689 690 Calling `unflatten()` on an object `#!json {"/1", [1,2,3]}`: 691 692 ``` 693 [json.exception.type_error.315] values in object must be primitive 694 ``` 695 696### json.exception.type_error.316 697 698The `dump()` function only works with UTF-8 encoded strings; that is, if you assign a `std::string` to a JSON value, make sure it is UTF-8 encoded. 699 700!!! failure "Example message" 701 702 Calling `dump()` on a JSON value containing an ISO 8859-1 encoded string: 703 ``` 704 [json.exception.type_error.316] invalid UTF-8 byte at index 15: 0x6F 705 ``` 706 707!!! tip 708 709 - Store the source file with UTF-8 encoding. 710 - Pass an error handler as last parameter to the `dump()` function to avoid this exception: 711 - `json::error_handler_t::replace` will replace invalid bytes sequences with `U+FFFD` 712 - `json::error_handler_t::ignore` will silently ignore invalid byte sequences 713 714### json.exception.type_error.317 715 716The dynamic type of the object cannot be represented in the requested serialization format (e.g. a raw `true` or `null` JSON object cannot be serialized to BSON) 717 718!!! failure "Example message" 719 720 Serializing `#!json null` to BSON: 721 ``` 722 [json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is null 723 ``` 724 Serializing `#!json [1,2,3]` to BSON: 725 ``` 726 [json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is array 727 ``` 728 729!!! tip 730 731 Encapsulate the JSON value in an object. That is, instead of serializing `#!json true`, serialize `#!json {"value": true}` 732 733## Out of range 734 735This exception is thrown in case a library function is called on an input parameter that exceeds the expected range, for instance in case of array indices or nonexisting object keys. 736 737Exceptions have ids 4xx. 738 739??? example 740 741 The following code shows how an `out_of_range` exception can be caught. 742 743 ```cpp 744 --8<-- "examples/out_of_range.cpp" 745 ``` 746 747 Output: 748 749 ``` 750 --8<-- "examples/out_of_range.output" 751 ``` 752 753### json.exception.out_of_range.401 754 755The provided array index `i` is larger than `size-1`. 756 757!!! failure "Example message" 758 759 ``` 760 array index 3 is out of range 761 ``` 762 763### json.exception.out_of_range.402 764 765The special array index `-` in a JSON Pointer never describes a valid element of the array, but the index past the end. That is, it can only be used to add elements at this position, but not to read it. 766 767!!! failure "Example message" 768 769 ``` 770 array index '-' (3) is out of range 771 ``` 772 773### json.exception.out_of_range.403 774 775The provided key was not found in the JSON object. 776 777!!! failure "Example message" 778 779 ``` 780 key 'foo' not found 781 ``` 782 783### json.exception.out_of_range.404 784 785A reference token in a JSON Pointer could not be resolved. 786 787!!! failure "Example message" 788 789 ``` 790 unresolved reference token 'foo' 791 ``` 792 793### json.exception.out_of_range.405 794 795The JSON Patch operations 'remove' and 'add' can not be applied to the root element of the JSON value. 796 797!!! failure "Example message" 798 799 ``` 800 JSON pointer has no parent 801 ``` 802 803### json.exception.out_of_range.406 804 805A parsed number could not be stored as without changing it to NaN or INF. 806 807!!! failure "Example message" 808 809 ``` 810 number overflow parsing '10E1000' 811 ``` 812 813### json.exception.out_of_range.407 814 815UBJSON and BSON only support integer numbers up to 9223372036854775807. 816 817!!! failure "Example message" 818 819 ``` 820 number overflow serializing '9223372036854775808' 821 ``` 822 823!!! note 824 825 Since version 3.9.0, integer numbers beyond int64 are serialized as high-precision UBJSON numbers, and this exception does not further occur. 826 827### json.exception.out_of_range.408 828 829The size (following `#`) of an UBJSON array or object exceeds the maximal capacity. 830 831!!! failure "Example message" 832 833 ``` 834 excessive array size: 8658170730974374167 835 ``` 836 837### json.exception.out_of_range.409 838 839Key identifiers to be serialized to BSON cannot contain code point U+0000, since the key is stored as zero-terminated c-string. 840 841!!! failure "Example message" 842 843 ``` 844 BSON key cannot contain code point U+0000 (at byte 2) 845 ``` 846 847## Further exceptions 848 849This exception is thrown in case of errors that cannot be classified with the 850other exception types. 851 852Exceptions have ids 5xx. 853 854??? example 855 856 The following code shows how an `other_error` exception can be caught. 857 858 ```cpp 859 --8<-- "examples/other_error.cpp" 860 ``` 861 862 Output: 863 864 ``` 865 --8<-- "examples/other_error.output" 866 ``` 867 868### json.exception.other_error.501 869 870A JSON Patch operation 'test' failed. The unsuccessful operation is also printed. 871 872!!! failure "Example message" 873 874 Executing `#!json {"op":"test", "path":"/baz", "value":"bar"}` on `#!json {"baz": "qux"}`: 875 876 ``` 877 [json.exception.other_error.501] unsuccessful: {"op":"test","path":"/baz","value":"bar"} 878 ``` 879