node-addon-api icon indicating copy to clipboard operation
node-addon-api copied to clipboard

std::exception catching once more

Open kamil321 opened this issue 6 months ago • 3 comments

Hi there. I might be beating a dead horse here (#601, #1225), but I have to try. I've got some bindings with thousands of functions and a lot of them like to throw exceptions. I was pretty shocked to find out that node just shuts down without any message when there's anything wrong. And that's of course because of the callback wrappers catching Napi::Error and nothing more.

I - kind of - understand that touching unknown exceptions sounds bad, but shutting down everything with neither a message nor a possibility to catch on the node end seems much, much worse. Leaving the choice to the developers is probably a good call, but not if they have to write the same try-catch 82394723 times.

I ended up modifying the header just like in this comment (e.what from std:exc, simple message from unknowns): https://github.com/nodejs/node-addon-api/issues/601#issuecomment-554614021 and some inner peace returned. At least until the next version upgrade.

Is this the perfect solution and should find its way into the api? No idea. But it could just lay there, hidden behind a global. Or maybe Napi could provide a way to inject a generic exception handler?

Thanks in advance for reconsidering.

kamil321 avatar Aug 12 '24 17:08 kamil321