From 02bbd9e68f9fcbf0564266fd857a27b2cf785445 Mon Sep 17 00:00:00 2001 From: Shun Moriya Date: Mon, 11 Jul 2022 00:13:27 +0900 Subject: [PATCH] replace throw with a macro. replace throw with a macro so that exception messages can be handled by the application. #148 --- picojson.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/picojson.h b/picojson.h index 76742fe..724e52f 100644 --- a/picojson.h +++ b/picojson.h @@ -96,11 +96,15 @@ extern "C" { } #endif +#ifndef PICOJSON_THROW +#define PICOJSON_THROW(e, m) throw e(m) +#endif + #ifndef PICOJSON_ASSERT #define PICOJSON_ASSERT(e) \ do { \ if (!(e)) \ - throw std::runtime_error(#e); \ + PICOJSON_THROW(std::runtime_error(#e)); \ } while (0) #endif @@ -251,8 +255,8 @@ inline value::value(double n) : type_(number_type), u_() { #else isnan(n) || isinf(n) #endif - ) { - throw std::overflow_error(""); + ) { + PICOJSON_THROW(std::overflow_error("")); } u_.number_ = n; }