-
Notifications
You must be signed in to change notification settings - Fork 10
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
Handle errors and return the callback without throwing #4
Comments
Put together an elegant solution for this today with @springmeyer and @GretaCB. Instead of using function inline void CallbackError(std::string message, v8::Local<v8::Function> callback) {
v8::Local<v8::Value> argv[1] = { Nan::Error(message.c_str()) };
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), callback, 1, argv);
} usage: CallbackError("this is my error message", callback); Important note - right now |
Another important note - it's still useful to throw instead of return errors in some cases (i.e. callback function not provided) - so this type of error throwing will still exist for example purposes. |
In #3 we are beginning to add checks for proper parameters and throwing errors if they are unexpected types. Currently we use the following approach:
In an asynchronous function, this throws instead of returning an error in the callback, which is a super big benefit of a callback function. To avoid this currently, we can wrap async functions in
try/catch
statements but that gets a bit clumsy.How can we better handle errors in the
.cpp
& Nan side of things so they are returned as errors instead of thrown?cc @springmeyer @GretaCB
The text was updated successfully, but these errors were encountered: