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
{{ message }}
Repository navigation
MSVC needs -D _HAS_EXCEPTIONS=1 for exceptions to work properly #85
Why? Can you explain what problem you're seeing without that define? There are tests of the exception behavior that seem to work fine without it.
As far as I know, _HAS_EXCEPTIONS=1 is the default for MSVC. Some projects may override it to 0. But in that case, they'd probably want 'NAPI_DISABLE_CPP_EXCEPTIONS instead.
Things work to some degree without it but there are subtle memory errors. I don't understand exactly what this flag causes but the effect is that objects are freed too early when handling an exception.
For instance try this with _HAS_EXCEPTIONS=0 and _HAS_EXCEPTIONS=1:
For me with MSVC 2015 this reliably prints '' with _HAS_EXCEPTIONS=0. But I've also encountered garbage memory in other cases. Needless to say this was a huge pain to debug and thus I think it should be much more prominently documented.
Hi @DBJDBJ,
thanks for reporting the paper about performance on error handling. node-addon-api allow you to enable or disable the exception mechanism.
It is documented on the following sections:
If you enable the exceptions you will have a little overhead and it could be acceptable or not
Many thanks for the quick comment. I appreciate the answer.
I might be so bold to think we (the native node.js community and customers) do require a bit more precise size and performance results than "you will have a little overhead..." ... has anyone (tasked by node team) measured the impact of exceptions recently? on the 3 key platforms with the 3 key compilers. I am trying to stay high level here. :)
@NickNaso This issue was closed but the documentation was never updated. Here's a simple example that doesn't catch correctly without "defines": ["_HAS_EXCEPTIONS=1"]:
Ok here is what precisely happens if one compiles with -D_HAS_EXCEPTIONS=0, on Windows.
_CPPUNWIND becomes 0. Keywords try,throw, catch cease to exist and WIN32 SEH aka "Structured Exceptions Handling" is being used everywhere like for example in MS STL.
This is primarily the side effect of using cl.exe (MSVC compiler) with the /kernel switch, to create kernel-mode DLL's.
Activity
jasongin commentedon Jul 21, 2017
Why? Can you explain what problem you're seeing without that define? There are tests of the exception behavior that seem to work fine without it.
As far as I know,
_HAS_EXCEPTIONS=1is the default for MSVC. Some projects may override it to 0. But in that case, they'd probably want'NAPI_DISABLE_CPP_EXCEPTIONSinstead.mika-fischer commentedon Jul 21, 2017
Things work to some degree without it but there are subtle memory errors. I don't understand exactly what this flag causes but the effect is that objects are freed too early when handling an exception.
For instance try this with
_HAS_EXCEPTIONS=0and_HAS_EXCEPTIONS=1:For me with MSVC 2015 this reliably prints
''with_HAS_EXCEPTIONS=0. But I've also encountered garbage memory in other cases. Needless to say this was a huge pain to debug and thus I think it should be much more prominently documented.The define comes from nodejs itself: https://github.com/nodejs/node/blob/master/common.gypi#L273
See also nodejs/node-gyp#939 which led me to the solution.
jasongin commentedon Jul 21, 2017
Interesting. Thanks for the details. And I didn't realize node
common.gypiset_HAS_EXCEPTIONS=0. I agree then it should be added to the README.DBJDBJ commentedon Jan 31, 2020
Abstract
The author measures size costs of error handling approaches. Exceptions are big,
std::abortand integer error codes are small.NickNaso commentedon Jan 31, 2020
Hi @DBJDBJ,
thanks for reporting the paper about performance on error handling.
node-addon-apiallow you to enable or disable the exception mechanism.It is documented on the following sections:
If you enable the exceptions you will have a little overhead and it could be acceptable or not.
I'm closing this because now the error handling for
node-addon-apiis documented like how it's possible to enable or disable the exception mechanism.DBJDBJ commentedon Jan 31, 2020
Many thanks for the quick comment. I appreciate the answer.
I might be so bold to think we (the native node.js community and customers) do require a bit more precise size and performance results than "you will have a little overhead..." ... has anyone (tasked by node team) measured the impact of exceptions recently? on the 3 key platforms with the 3 key compilers. I am trying to stay high level here. :)
zbjornson commentedon Sep 1, 2021
@NickNaso This issue was closed but the documentation was never updated. Here's a simple example that doesn't catch correctly without
"defines": ["_HAS_EXCEPTIONS=1"]:NickNaso commentedon Sep 1, 2021
Hi @zbjornson,
sorry I made a mistake on closing the issue. Now i'm preparing a PR to solve the problem. Thanks for your feedback.
DBJDBJ commentedon Sep 2, 2021
Ok here is what precisely happens if one compiles with
-D_HAS_EXCEPTIONS=0, on Windows._CPPUNWINDbecomes 0. Keywordstry,throw,catchcease to exist and WIN32 SEH aka "Structured Exceptions Handling" is being used everywhere like for example in MS STL.This is primarily the side effect of using cl.exe (MSVC compiler) with the
/kernelswitch, to create kernel-mode DLL's.May thanks ...