murgatroid99 murgatroid99 - 1 year ago 64
C++ Question

How should I throw an error with a numeric code in NAN 1.x?

In NAN 1.9, the

NanThrowError(const char *msg, const int errorNumber)
method was deprecated, and it looks like an equivalent method is not present in NAN 2.0. Is there another way to get this same functionality with NAN, or is it just gone entirely?

Answer Source

It was removed because it was unnecessary, easily implemented as needed.

inline v8::Local<v8::Value> makeErrorWithCode(const char *msg, int code) {
    v8::Local<v8::Object> err = NanError(msg).As<v8::Object>();
    err->Set(NanNew("code"), NanNew<v8::Int32>(code));
    return NanEscapeScope(err);

return NanThrowError(makeErrorWithCode("message", 1337));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download