Skip to content

Proposed macro to override throw #148

@shun126

Description

@shun126

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions