This class is an extension of std::exception
objects with a member id for exception ids. It is used as the base class for all exceptions thrown by the basic_json class. This class can hence be used as "wildcard" to catch exceptions.
Subclasses:
- parse_error for exceptions indicating a parse error
- invalid_iterator for exceptions indicating errors with iterators
- type_error for exceptions indicating executing a member function with a wrong type
- out_of_range for exceptions indicating access out of the defined range
- other_error for exceptions indicating other library errors
- Example
- The following code shows how arbitrary library exceptions can be caught.
2 #include <nlohmann/json.hpp>
11 json j = {{
"foo",
"bar"}};
12 json k = j.at(
"non-existing");
17 std::cout <<
"message: " << e.what() <<
'\n'
18 <<
"exception id: " << e.id << std::endl;
Output (play with this example online): message: [json.exception.out_of_range.403] key 'non-existing' not found
exception id: 403
The example code above can be translated withg++ -std=c++11 -Isingle_include doc/examples/exception.cpp -o exception
- Since
- version 3.0.0
Definition at line 14774 of file json.hpp.