summaryrefslogtreecommitdiff
path: root/rapidjsonwrapper.h
diff options
context:
space:
mode:
authorPeter LaFosse <peter@vector35.com>2019-09-26 08:14:40 -0400
committerPeter LaFosse <peter@vector35.com>2019-09-26 15:32:02 -0400
commitfac72eeca68e1c85647159fb557daf759020d8d5 (patch)
tree09930951728f33be038a2162e5c04dc7d6d25c5b /rapidjsonwrapper.h
parent9d4816ec8b961faeaa31e785b846e7e099e7920c (diff)
Add rapidjsonwrapper to add exceptions rather than asserts on failure
Diffstat (limited to 'rapidjsonwrapper.h')
-rw-r--r--rapidjsonwrapper.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/rapidjsonwrapper.h b/rapidjsonwrapper.h
new file mode 100644
index 00000000..cf3dd829
--- /dev/null
+++ b/rapidjsonwrapper.h
@@ -0,0 +1,33 @@
+#pragma once
+#include <exception>
+#include <stdexcept>
+
+struct GenericException;
+struct ParseException;
+
+struct GenericException: public std::exception
+{
+ GenericException() : std::exception() {}
+ virtual const char* what() const throw()
+ {
+ return "Exception while parsing json.";
+ }
+};
+
+#define RAPIDJSON_HAS_STDSTRING 1
+#define RAPIDJSON_HAS_CXX11_NOEXCEPT 0
+#define RAPIDJSON_ASSERT(x) do {if (!(x)) throw GenericException(); } while(0);
+#define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode,offset) \
+ throw ParseException(parseErrorCode, #parseErrorCode, offset)
+
+#include "rapidjson/error/error.h"
+struct ParseException: public std::runtime_error, rapidjson::ParseResult
+{
+ ParseException(rapidjson::ParseErrorCode code, const char* msg, size_t offset) : std::runtime_error(msg),
+ ParseResult(code, offset) {}
+};
+
+#include "rapidjson/rapidjson.h"
+#include "rapidjson/document.h"
+
+