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

Allow overriding JSON_THROW to something else than abort() #938

Closed
kaidokert opened this issue Jan 27, 2018 · 3 comments
Closed

Allow overriding JSON_THROW to something else than abort() #938

kaidokert opened this issue Jan 27, 2018 · 3 comments
Assignees
Labels
kind: enhancement/improvement solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@kaidokert
Copy link
Contributor

kaidokert commented Jan 27, 2018

Feature Request

  • Describe the feature in as much detail as possible.

On an embedded/rtos system, the stack is compiled without rtti/exceptions, and I'm running http workers in a separate thread. I can deal with failures by basically tearing the thread down and restarting it, however, i don't want to call abort() specifically and unconditionally. Also it's nice to still be able to obtain the error code from the exception

  • Include sample usage where appropriate.

passing a -DJSON_THROW=my_deal_with_json_error(x) at compile time would allow easy customization of how the error handling gets dealt with

The addition is as simple as

#if !defined(JSON_THROW)
#define JSON_THROW abort
#endif
@nlohmann
Copy link
Owner

That seems like a reasonable extension, but maybe also for JSON_TRY and JSON_CATCH. What do you think?

@kaidokert
Copy link
Contributor Author

kaidokert commented Jan 28, 2018

I thought about that and didn't immediately think of a valid use case, but maybe doing something like

#define JSON_TRY(x) if(my_save_last_try_point(..., ___FILE__, ___LINE__ ) || true) 

could be useful in debugging scenarios. I'll add and make a PR in a bit

kaidokert pushed a commit to kaidokert/json that referenced this issue Jan 28, 2018
nlohmann added a commit that referenced this issue Jan 29, 2018
Allow overriding THROW/CATCH/TRY macros with no-exceptions #938
@nlohmann nlohmann added this to the Release 3.1.0 milestone Jan 29, 2018
@nlohmann nlohmann self-assigned this Jan 29, 2018
@nlohmann
Copy link
Owner

Fixed with merged PR #940.

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Jan 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement/improvement solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants