This commit is contained in:
nlohmann committed 2026-10-12 07:35:31 +00:00
1 parent 79119509a9
commit 22fba27145
555 files changed
+17342 -1394

No files matched your search

+25 -2
View File
@@ -55,13 +55,36 @@ classDiagram
The following code shows how a `invalid_iterator` exception can be caught.
```cpp
--8<-- "examples/invalid_iterator.cpp"
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
try
{
// calling iterator::key() on non-object iterator
json j = "string";
json::iterator it = j.begin();
auto k = it.key();
}
catch (const json::invalid_iterator& e)
{
// output exception information
std::cout << "message: " << e.what() << '\n'
<< "exception id: " << e.id << std::endl;
}
}
```
Output:
```json
--8<-- "examples/invalid_iterator.output"
message: [json.exception.invalid_iterator.207] cannot use key() for non-object iterators
exception id: 207
```
## See also