Skip to content

Commit

Permalink
add PICOJSON_DISABLE_EXCEPTION macro to support -fno-exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed May 28, 2019
1 parent 8ba7113 commit ae24181
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions picojson.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,19 @@ extern "C" {
#endif

#ifndef PICOJSON_ASSERT
#ifndef PICOJSON_DISABLE_EXCEPTION
#define PICOJSON_ASSERT(e) \
do { \
if (!(e)) \
throw std::runtime_error(#e); \
} while (0)
#else
#define PICOJSON_ASSERT(e) \
do { \
if (!(e)) \
std::abort(); \
} while (0)
#endif // PICOJSON_DISABLE_EXCEPTION
#endif

#ifdef _MSC_VER
Expand Down Expand Up @@ -245,7 +253,11 @@ inline value::value(double n) : type_(number_type), u_() {
isnan(n) || isinf(n)
#endif
) {
#ifndef PICOJSON_DISABLE_EXCEPTION
throw std::overflow_error("");
#else
std::abort();
#endif
}
u_.number_ = n;
}
Expand Down

0 comments on commit ae24181

Please sign in to comment.