@brief general exception of the @ref basic_json class @sa https://json.nlohmann.me/api/basic_json/exception/
| 4298 | /// @brief general exception of the @ref basic_json class |
| 4299 | /// @sa https://json.nlohmann.me/api/basic_json/exception/ |
| 4300 | class exception : public std::exception |
| 4301 | { |
| 4302 | public: |
| 4303 | /// returns the explanatory string |
| 4304 | const char* what() const noexcept override |
| 4305 | { |
| 4306 | return m.what(); |
| 4307 | } |
| 4308 | |
| 4309 | /// the id of the exception |
| 4310 | const int id; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) |
| 4311 | |
| 4312 | protected: |
| 4313 | JSON_HEDLEY_NON_NULL(3) |
| 4314 | exception(int id_, const char* what_arg) : id(id_), m(what_arg) {} // NOLINT(bugprone-throw-keyword-missing) |
| 4315 | |
| 4316 | static std::string name(const std::string& ename, int id_) |
| 4317 | { |
| 4318 | return concat("[json.exception.", ename, '.', std::to_string(id_), "] "); |
| 4319 | } |
| 4320 | |
| 4321 | static std::string diagnostics(std::nullptr_t /*leaf_element*/) |
| 4322 | { |
| 4323 | return ""; |
| 4324 | } |
| 4325 | |
| 4326 | template<typename BasicJsonType> |
| 4327 | static std::string diagnostics(const BasicJsonType* leaf_element) |
| 4328 | { |
| 4329 | #if JSON_DIAGNOSTICS |
| 4330 | std::vector<std::string> tokens; |
| 4331 | for (const auto* current = leaf_element; current != nullptr && current->m_parent != nullptr; current = current->m_parent) |
| 4332 | { |
| 4333 | switch (current->m_parent->type()) |
| 4334 | { |
| 4335 | case value_t::array: |
| 4336 | { |
| 4337 | for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i) |
| 4338 | { |
| 4339 | if (¤t->m_parent->m_value.array->operator[](i) == current) |
| 4340 | { |
| 4341 | tokens.emplace_back(std::to_string(i)); |
| 4342 | break; |
| 4343 | } |
| 4344 | } |
| 4345 | break; |
| 4346 | } |
| 4347 | |
| 4348 | case value_t::object: |
| 4349 | { |
| 4350 | for (const auto& element : *current->m_parent->m_value.object) |
| 4351 | { |
| 4352 | if (&element.second == current) |
| 4353 | { |
| 4354 | tokens.emplace_back(element.first.c_str()); |
| 4355 | break; |
| 4356 | } |
| 4357 | } |
no outgoing calls