-
Notifications
You must be signed in to change notification settings - Fork 465
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
Catch all exceptions #601
Comments
We catch only exceptions with which we know what to do. We know that we can turn a thrown Napi::Error::New(env, "CallbackWrapper", "A native exception was thrown")
.ThrowAsJavaScriptException(); before returning to JavaScript. This would mean that we basically swallow the native exception and replace it with a IMO if applications throw something other than We could start adding convenience handlers for, like, |
Letting a whole nodejs crash is really a worse idea.
A customizable exception mapper is nice feature. However the default one can catch only try {
return callback();
} catch (const Error& e) {
e.ThrowAsJavaScriptException();
} catch (const std::exception &e) {
Napi::Error::New(env, "CallbackWrapper", e.what()).ThrowAsJavaScriptException();
} catch (...) {
Napi::Error::New(env, "CallbackWrapper", "A native exception was thrown").ThrowAsJavaScriptException();
}
return nullptr; Throw anything except derived from |
Why not call
This would have saved us a lot of boilerplate. |
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made. |
Currently only Error is caught. It is better to catch all exceptions otherwise an user has to use try..catch in each callback/function.
The text was updated successfully, but these errors were encountered: