Proposed macro to override throw
shun126 opened this issue · 0 comments
shun126 commented
The issue of switching throw to abort is similar to #117 and #118.
In this assignment, replace throw with a macro so that exception messages can be handled by the application.
Prepare a macro named PICOJSON_THROW
.
// add new macro
#ifndef PICOJSON_THROW
#define PICOJSON_THROW(e, m) throw e(m)
#endif
// replace throw
#ifndef PICOJSON_ASSERT
#define PICOJSON_ASSERT(e) \
do { \
if (!(e)) \
PICOJSON_THROW(std::runtime_error, #e); \
} while (0)
#endif
The application side overwrites abort and assert to use it.
#define PICOJSON_THROW(e, m) { puts(#e ":" m); abort(); }