MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / parse_error

Class parse_error

Source/Utils/json.hpp:2424–2471  ·  view source on GitHub ↗

! @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.

Source from the content-addressed store, hash-verified

2422 @since version 3.0.0
2423 */
2424 class parse_error : public exception
2425 {
2426 public:
2427 /*!
2428 @brief create a parse error exception
2429 @param[in] id_ the id of the exception
2430 @param[in] pos the position where the error occurred (or with
2431 chars_read_total=0 if the position cannot be
2432 determined)
2433 @param[in] what_arg the explanatory string
2434 @return parse_error object
2435 */
2436 static parse_error create(int id_, const position_t& pos, const std::string& what_arg)
2437 {
2438 std::string w = exception::name("parse_error", id_) + "parse error" +
2439 position_string(pos) + ": " + what_arg;
2440 return parse_error(id_, pos.chars_read_total, w.c_str());
2441 }
2442
2443 static parse_error create(int id_, std::size_t byte_, const std::string& what_arg)
2444 {
2445 std::string w = exception::name("parse_error", id_) + "parse error" +
2446 (byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") +
2447 ": " + what_arg;
2448 return parse_error(id_, byte_, w.c_str());
2449 }
2450
2451 /*!
2452 @brief byte index of the parse error
2453
2454 The byte index of the last read character in the input file.
2455
2456 @note For an input with n bytes, 1 is the index of the first character and
2457 n+1 is the index of the terminating null byte or the end of file.
2458 This also holds true when reading a byte vector (CBOR or MessagePack).
2459 */
2460 const std::size_t byte;
2461
2462 private:
2463 parse_error(int id_, std::size_t byte_, const char* what_arg)
2464 : exception(id_, what_arg), byte(byte_) {}
2465
2466 static std::string position_string(const position_t& pos)
2467 {
2468 return " at line " + std::to_string(pos.lines_read + 1) +
2469 ", column " + std::to_string(pos.chars_read_current_line);
2470 }
2471 };
2472
2473 /*!
2474 @brief exception indicating errors with iterators

Callers 1

createMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected