json/except: use a human readable key_error message

the exception string was completely useless without mentioning "you
tried to dereference an invalid key".
This commit is contained in:
Danny Robson 2016-06-29 17:55:44 +10:00
parent 6e533e47b7
commit 10e0c4f923
2 changed files with 7 additions and 2 deletions

View File

@ -16,6 +16,8 @@
#include "except.hpp"
#include "../format.hpp"
///////////////////////////////////////////////////////////////////////////////
json::parse_error::parse_error (const std::string &_what, size_t _line):
@ -34,6 +36,7 @@ json::parse_error::what (void) const noexcept
///////////////////////////////////////////////////////////////////////////////
json::key_error::key_error (std::string _what):
error (std::move (_what))
json::key_error::key_error (std::string _key):
error (util::format::render ("missing key '%s'", _key)),
key (_key)
{ ; }

View File

@ -54,6 +54,8 @@ namespace json {
/// Exception class for invalid object indexing
struct key_error : public error {
explicit key_error (std::string);
std::string key;
};
}