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

+24 -2
View File
@@ -69,13 +69,35 @@ constructor.
The following code shows how arbitrary library exceptions can be caught.
```cpp
--8<-- "examples/exception.cpp"
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
try
{
// calling at() for a non-existing key
json j = {{"foo", "bar"}};
json k = j.at("non-existing");
}
catch (const json::exception& e)
{
// output exception information
std::cout << "message: " << e.what() << '\n'
<< "exception id: " << e.id << std::endl;
}
}
```
Output:
```json
--8<-- "examples/exception.output"
message: [json.exception.out_of_range.403] key 'non-existing' not found
exception id: 403
```
## See also