You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The documentation states "On return from a native method, node-addon-api will automatically convert a pending C++ exception to a JavaScript exception." but in InstanceMethodCallbackWrapper when I call a C++ API that throws std::exception, std::terminate is called because no exception handler is installed. If I wrap my call in something like
addon.MethodNapiExcpetion()
^
Error: Napi exception
at Object.<anonymous> (/Users/nicoladelgobbo/Downloads/addon/index.js:6:7)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:82:12)
at node:internal/main/run_main_module:23:47
Node.js v19.0.0
We had some discusssion about this in the past in this issue #601. The proble is the we don't know what you want to do when a C++ exception will thrown and for now we leaved this respnsibility to the developer bucause we were unsure that trasform a Cpp exception could be the best option.
At least the documentation should be changed, do you want to make a PR?
Activity
mhdawson commentedon Oct 28, 2022
Do you have a simple recreate that we can turn into a test ?
NickNaso commentedon Nov 3, 2022
Hi @froody,
you're right only the exception of type
Napi::Errorare autimatically converted to a JavaScript exception.If you call
MethodCppExcpetionfrom your JavaScript code:you will get something like this:
If you call
MethodNapiExcpetionfrom your JavaScript code:you will get something like this:
We had some discusssion about this in the past in this issue #601. The proble is the we don't know what you want to do when a C++ exception will thrown and for now we leaved this respnsibility to the developer bucause we were unsure that trasform a Cpp exception could be the best option.
At least the documentation should be changed, do you want to make a PR?
mhdawson commentedon Nov 18, 2022
Discussed in the Node-API team meeting today and @NickNaso is going to update the docs to make it clearer.
NickNaso commentedon Jan 13, 2023
I'm closing we updated the documentation through this PR #1241.