! @brief exception indicating a parse error This exception is thrown by the library when a parse error occurs. Parse errors can occur during the deserialization of JSON text, CBOR, MessagePack, as well as when using JSON Patch. Member @a byte holds the byte index of the last read character in the input file. Exceptions have ids 1xx. name / id | example message | descriptio
| 2489 | @since version 3.0.0 |
| 2490 | */ |
| 2491 | class parse_error : public exception |
| 2492 | { |
| 2493 | public: |
| 2494 | /*! |
| 2495 | @brief create a parse error exception |
| 2496 | @param[in] id_ the id of the exception |
| 2497 | @param[in] pos the position where the error occurred (or with |
| 2498 | chars_read_total=0 if the position cannot be |
| 2499 | determined) |
| 2500 | @param[in] what_arg the explanatory string |
| 2501 | @return parse_error object |
| 2502 | */ |
| 2503 | static parse_error create(int id_, const position_t& pos, const std::string& what_arg) |
| 2504 | { |
| 2505 | std::string w = exception::name("parse_error", id_) + "parse error" + |
| 2506 | position_string(pos) + ": " + what_arg; |
| 2507 | return parse_error(id_, pos.chars_read_total, w.c_str()); |
| 2508 | } |
| 2509 | |
| 2510 | static parse_error create(int id_, std::size_t byte_, const std::string& what_arg) |
| 2511 | { |
| 2512 | std::string w = exception::name("parse_error", id_) + "parse error" + |
| 2513 | (byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") + |
| 2514 | ": " + what_arg; |
| 2515 | return parse_error(id_, byte_, w.c_str()); |
| 2516 | } |
| 2517 | |
| 2518 | /*! |
| 2519 | @brief byte index of the parse error |
| 2520 | |
| 2521 | The byte index of the last read character in the input file. |
| 2522 | |
| 2523 | @note For an input with n bytes, 1 is the index of the first character and |
| 2524 | n+1 is the index of the terminating null byte or the end of file. |
| 2525 | This also holds true when reading a byte vector (CBOR or MessagePack). |
| 2526 | */ |
| 2527 | const std::size_t byte; |
| 2528 | |
| 2529 | private: |
| 2530 | parse_error(int id_, std::size_t byte_, const char* what_arg) |
| 2531 | : exception(id_, what_arg), byte(byte_) {} |
| 2532 | |
| 2533 | static std::string position_string(const position_t& pos) |
| 2534 | { |
| 2535 | return " at line " + std::to_string(pos.lines_read + 1) + |
| 2536 | ", column " + std::to_string(pos.chars_read_current_line); |
| 2537 | } |
| 2538 | }; |
| 2539 | |
| 2540 | /*! |
| 2541 | @brief exception indicating errors with iterators |