7 #include <nlohmann/detail/input/position_t.hpp>
8 #include <nlohmann/detail/macro_scope.hpp>
46 class exception :
public std::exception
50 JSON_HEDLEY_RETURNS_NON_NULL
51 const char*
what() const noexcept
override
60 JSON_HEDLEY_NON_NULL(3)
61 exception(
int id_, const
char* what_arg) :
id(id_), m(what_arg) {}
63 static std::string name(
const std::string& ename,
int id_)
65 return "[json.exception." + ename +
"." + std::to_string(id_) +
"] ";
117 class parse_error :
public exception
131 std::string w = exception::name(
"parse_error", id_) +
"parse error" +
132 position_string(pos) +
": " + what_arg;
136 static parse_error create(
int id_, std::size_t byte_,
const std::string& what_arg)
138 std::string w = exception::name(
"parse_error", id_) +
"parse error" +
139 (byte_ != 0 ? (
" at byte " + std::to_string(byte_)) :
"") +
153 const std::size_t
byte;
156 parse_error(
int id_, std::size_t byte_,
const char* what_arg)
157 : exception(id_, what_arg),
byte(byte_) {}
159 static std::string position_string(
const position_t& pos)
161 return " at line " + std::to_string(pos.lines_read + 1) +
162 ", column " + std::to_string(pos.chars_read_current_line);
203 class invalid_iterator :
public exception
206 static invalid_iterator create(
int id_,
const std::string& what_arg)
208 std::string w = exception::name(
"invalid_iterator", id_) + what_arg;
209 return invalid_iterator(id_, w.c_str());
213 JSON_HEDLEY_NON_NULL(3)
214 invalid_iterator(
int id_, const
char* what_arg)
215 : exception(id_, what_arg) {}
257 class type_error :
public exception
260 static type_error create(
int id_,
const std::string& what_arg)
262 std::string w = exception::name(
"type_error", id_) + what_arg;
263 return type_error(id_, w.c_str());
267 JSON_HEDLEY_NON_NULL(3)
268 type_error(
int id_, const
char* what_arg) : exception(id_, what_arg) {}
304 class out_of_range :
public exception
307 static out_of_range create(
int id_,
const std::string& what_arg)
309 std::string w = exception::name(
"out_of_range", id_) + what_arg;
310 return out_of_range(id_, w.c_str());
314 JSON_HEDLEY_NON_NULL(3)
315 out_of_range(
int id_, const
char* what_arg) : exception(id_, what_arg) {}
342 class other_error :
public exception
345 static other_error create(
int id_,
const std::string& what_arg)
347 std::string w = exception::name(
"other_error", id_) + what_arg;
348 return other_error(id_, w.c_str());
352 JSON_HEDLEY_NON_NULL(3)
353 other_error(
int id_, const
char* what_arg) : exception(id_, what_arg) {}