! @brief general exception of the @ref basic_json class This class is an extension of `std::exception` objects with a member @a id for exception ids. It is used as the base class for all exceptions thrown by the @ref basic_json class. This class can hence be used as "wildcard" to catch exceptions. Subclasses: - @ref parse_error for exceptions indicating a parse error - @ref invalid_iterator for
| 2417 | @since version 3.0.0 |
| 2418 | */ |
| 2419 | class exception : public std::exception |
| 2420 | { |
| 2421 | public: |
| 2422 | /// returns the explanatory string |
| 2423 | JSON_HEDLEY_RETURNS_NON_NULL |
| 2424 | const char* what() const noexcept override |
| 2425 | { |
| 2426 | return m.what(); |
| 2427 | } |
| 2428 | |
| 2429 | /// the id of the exception |
| 2430 | const int id; |
| 2431 | |
| 2432 | protected: |
| 2433 | JSON_HEDLEY_NON_NULL(3) |
| 2434 | exception(int id_, const char* what_arg) : id(id_), m(what_arg) {} |
| 2435 | |
| 2436 | static std::string name(const std::string& ename, int id_) |
| 2437 | { |
| 2438 | return "[json.exception." + ename + "." + std::to_string(id_) + "] "; |
| 2439 | } |
| 2440 | |
| 2441 | private: |
| 2442 | /// an exception object as storage for error messages |
| 2443 | std::runtime_error m; |
| 2444 | }; |
| 2445 | |
| 2446 | /*! |
| 2447 | @brief exception indicating a parse error |
no outgoing calls
no test coverage detected