-
There's difficulty to find a specific line of JSON file which causes a certain error. In the project, we have many structures with Example: So the quickest solution for me was adding try catches in sources: struct from_json_fn
{
template<typename BasicJsonType, typename T>
auto operator()(const BasicJsonType& j, T& val) const
noexcept(noexcept(from_json(j, val)))
-> decltype(from_json(j, val), void())
{
try
{
return from_json(j, val);
}
catch (const std::exception &ex)
{
std::cerr << "[NLOHMANN from_json error ]]: " << j << std::endl;
throw;
}
}
}; Are there any better approaches for this case? The idea is to find a specific example with an error from the file I would love to see something like this: try
{
// parsing input with a syntax error
nlohmann::json::parse(myJsonFile);
}
catch (nlohmann::json::parse_error& e)
{
// output exception information
std::cout << "message: " << e.what() << '\n'
<< "exception id: " << e.id << '\n'
<< "byte position of error: " << e.byte << std::endl;
} But there isn't |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
FYI: I am trying to fix this issue in #2562. Any help would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
FYI: I am trying to fix this issue in #2562. Any help would be greatly appreciated!