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

Open
shun126 opened this issue Jun 22, 2022 · 0 comments
Open

Proposed macro to override throw #148

shun126 opened this issue Jun 22, 2022 · 0 comments

Comments

@shun126
Copy link

shun126 commented Jun 22, 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 a commit to shun126/picojson that referenced this issue Jul 10, 2022
replace throw with a macro so that exception messages can be handled by the application. kazuho#148
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

No branches or pull requests

1 participant