Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed macro to override throw #148 #149

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

shun126
Copy link

@shun126 shun126 commented Jul 14, 2022

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(); }

shun126 added 2 commits July 11, 2022 00:13
replace throw with a macro so that exception messages can be handled by the application. kazuho#148
Fixed incorrect specification of PICOJSON_THROW argument.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant