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

feat: allow catching all exceptions #1593

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

KevinEady
Copy link
Contributor

@KevinEady KevinEady commented Oct 18, 2024

Adds new compile-time define (NAPI_CPP_EXCEPTIONS_ALL) to enable catching all exceptions.

Must be under a flag to be semver minor.

TODO:

  • docs
  • tests

Fixes: #1555

@KevinEady
Copy link
Contributor Author

I'd like to discuss the naming of the new define NAPI_CPP_EXCEPTIONS_ALL ... to go with convention it should be NODE_ADDON_API_CPP_EXCEPTIONS_ALL.

We can use NODE_ADDON_API_CPP_EXCEPTIONS_ALL and introduce NODE_ADDON_API_CPP_EXCEPTIONS as a (backwards-compatible) replacement for NAPI_CPP_EXCEPTIONS_ALL ?

@KevinEady
Copy link
Contributor Author

We discuss in the 18 Oct Node-API meeting:

  • Use the NODE_ADDON_API_ prefix on the defines
  • Should the "catch all" be the new default?
    • What about some best practices doc? We also mentioned this with the requiring basic finalizers option

@@ -78,43 +78,61 @@ inline napi_status AttachData(napi_env env,
// For use in JS to C++ callback wrappers to catch any Napi::Error exceptions
// and rethrow them as JavaScript exceptions before returning from the callback.
template <typename Callable>
inline napi_value WrapCallback(Callable callback) {
#ifdef NAPI_CPP_EXCEPTIONS
inline napi_value WrapCallback(napi_env env, Callable callback) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are adding the env parameter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is needed to construct a new Error object.

Copy link
Member

@NickNaso NickNaso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this branch in sync with the main?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Need Triage
Development

Successfully merging this pull request may close these issues.

std::exception catching once more
3 participants