! @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
| 143 | @since version 3.0.0 |
| 144 | */ |
| 145 | class exception : public std::exception |
| 146 | { |
| 147 | public: |
| 148 | /// returns the explanatory string |
| 149 | const char* what() const noexcept override |
| 150 | { |
| 151 | return m.what(); |
| 152 | } |
| 153 | |
| 154 | /// the id of the exception |
| 155 | const int id; |
| 156 | |
| 157 | protected: |
| 158 | exception(int id_, const char* what_arg) : id(id_), m(what_arg) {} |
| 159 | |
| 160 | static std::string name(const std::string& ename, int id_) |
| 161 | { |
| 162 | return "[json.exception." + ename + "." + std::to_string(id_) + "] "; |
| 163 | } |
| 164 | |
| 165 | private: |
| 166 | /// an exception object as storage for error messages |
| 167 | std::runtime_error m; |
| 168 | }; |
| 169 | |
| 170 | /*! |
| 171 | @brief exception indicating a parse error |
nothing calls this directly
no outgoing calls
no test coverage detected