|
Boost : |
From: Kenneth Porter (shiva_at_[hidden])
Date: 2022-04-25 20:54:43
I'm using Boost.JSON to load some static data into a tree of structures.
The parser throws exceptions on parse errors, and I print the
std::exception::what() string. (I throw them up in a messagebox in my GUI.)
I see things like "not a number" when parsing a string where a number was
expected. But I don't see any information on where in the source string the
parse error happened so I have to set a breakpoint in my tag_invoke
functions to figure out where the syntax errors lie. Is there some way to
get the library to report the offset in the source string to where the
parse error happens as part of the exception?
Here's my top-level invocation:
#include <fstream>
#include <stdexcept>
#define BOOST_DLL_USE_STD_FS 1 // tell program_location to return a
std::filesystem::path
#include <boost/dll/runtime_symbol_info.hpp> // program_location
#include <boost/json/src.hpp> // header-only implementation
std::ifstream
is(boost::dll::program_location().replace_extension("json"));
std::string contents;
contents.assign(std::istreambuf_iterator<char>(is),
std::istreambuf_iterator<char>());
boost::json::value jv = boost::json::parse(contents);
axes = boost::json::value_to<std::vector<AxisProperties>
>(jv.as_object().at("axis"));
Library source and background: <https://github.com/boostorg/json>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk