This is a duplicate of #669
When a JS callback called from a ThreadSafeFunction throws an exception, the result is:
terminate called after throwing an instance of 'Napi::Error'
what(): unexpected error
Aborted (core dumped)
While this:
setImmediate(() => {
throw new Error('unexpected error');
});
ends up like this:
/home/mmom/src/exprtk.js/uncaught.js:2
throw new Error('err');
^
Error: err
at Immediate.<anonymous> (/home/mmom/src/exprtk.js/uncaught.js:2:9)
at processImmediate (internal/timers.js:464:21)
Why is it such a big deal? Because, as a module author, the first one will surely end up in an issue for my module, while with the second one, the user will correctly recognize what is happening.
Ideally, there should be a way to call Node's internal method which terminates the process.