From 5088ccdc46c37db4cd95574575b8afd83113f839 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Fri, 16 Dec 2022 16:03:22 -0500 Subject: Use file/line numbers in rapidjson generic errors --- rapidjsonwrapper.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'rapidjsonwrapper.h') diff --git a/rapidjsonwrapper.h b/rapidjsonwrapper.h index e12465d6..a6775857 100644 --- a/rapidjsonwrapper.h +++ b/rapidjsonwrapper.h @@ -13,8 +13,12 @@ struct ParseException; struct GenericException : public std::exception { - GenericException() : std::exception() {} - virtual const char* what() const throw() { return "Exception while parsing json."; } + char text[0x200]; + GenericException(const char* file, int line, const char* description) : std::exception() { + snprintf(text, sizeof(text), "%s:%d: %s", file, line, description); + } + virtual const char* what() const throw() + { return text; } }; #define RAPIDJSON_HAS_STDSTRING 0 @@ -23,7 +27,7 @@ struct GenericException : public std::exception do \ { \ if (!(x)) \ - throw GenericException(); \ + throw GenericException(__FILE__, __LINE__, #x); \ } while (0); #define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset) \ throw ParseException(parseErrorCode, #parseErrorCode, offset) -- cgit v1.3.1