MCPcopy Index your code
hub / github.com/nodejs/node-addon-api / ThrowDefaultError

Function ThrowDefaultError

test/error.cc:362–396  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

360}
361
362void ThrowDefaultError(const CallbackInfo& info) {
363 napi_value dummy;
364 napi_env env = info.Env();
365 napi_status status = napi_get_undefined(env, &dummy);
366 NAPI_FATAL_IF_FAILED(status, "ThrowDefaultError", "napi_get_undefined");
367
368 if (info[0].As<Boolean>().Value()) {
369 // Provoke Node-API into setting an error, then use the `Napi::Error::New`
370 // factory with only the `env` parameter to throw an exception generated
371 // from the last error.
372 uint32_t dummy_uint32;
373 status = napi_get_value_uint32(env, dummy, &dummy_uint32);
374 if (status == napi_ok) {
375 Error::Fatal("ThrowDefaultError", "napi_get_value_uint32");
376 }
377 // We cannot use `NAPI_THROW_IF_FAILED()` here because we do not wish
378 // control to pass back to the engine if we throw an exception here and C++
379 // exceptions are turned on.
380 Napi::Error::New(env).ThrowAsJavaScriptException();
381 }
382
383 // Produce and throw a second error that has different content than the one
384 // above. If the one above was thrown, then throwing the one below should
385 // have the effect of re-throwing the one above.
386 status = napi_get_named_property(env, dummy, "xyzzy", &dummy);
387 if (status == napi_ok) {
388 Error::Fatal("ThrowDefaultError", "napi_get_named_property");
389 }
390
391 ReleaseAndWaitForChildProcess(info, 1);
392
393 // The macro creates a `Napi::Error` using the factory that takes only the
394 // env, however, it heeds the exception mechanism to be used.
395 NAPI_THROW_IF_FAILED_VOID(env, status);
396}
397
398} // end anonymous namespace
399

Callers

nothing calls this directly

Calls 4

EnvMethod · 0.80
ValueMethod · 0.80

Tested by

no test coverage detected