tgockel / json-voorhees

A killer modern C++ library for interacting with JSON.
http://tgockel.github.io/json-voorhees/
Apache License 2.0
129 stars 18 forks source link

serialization: Throw an `extraction_error` on missing keys. #130

Closed tgockel closed 5 years ago

tgockel commented 5 years ago

Previously, missing keys would simply be left uninitialized, which was slightly problematic. In usage, this would invoke undefined behavior and also violated the serialization builder documentation:

If a default_value is not specified, the key is required.

This changeset also changes the error message thrown from extraction_context::extract and extraction_context::extract_sub when the type does not derive from std::exception to attempt to extract the exception type from the CXXABI (if available in C++17). This uses a different detection mechanism than demangle.cpp, which just looks for the non-presence of _MSC_VER. This should be change in 2.0.

Fixes issue #124.