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

Method Catch

napi-inl.h:3037–3058  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3035}
3036
3037inline MaybeOrValue<Promise> Promise::Catch(napi_value onRejected) const {
3038 EscapableHandleScope scope(_env);
3039#ifdef NODE_ADDON_API_ENABLE_MAYBE
3040 Value catchMethod;
3041 if (!Get("catch").UnwrapTo(&catchMethod)) {
3042 return Nothing<Promise>();
3043 }
3044 MaybeOrValue<Value> result =
3045 catchMethod.As<Function>().Call(*this, {onRejected});
3046 if (result.IsJust()) {
3047 return Just(scope.Escape(result.Unwrap()).As<Promise>());
3048 }
3049 return Nothing<Promise>();
3050#else
3051 Function catchMethod = Get("catch").As<Function>();
3052 MaybeOrValue<Value> result = catchMethod.Call(*this, {onRejected});
3053 if (scope.Env().IsExceptionPending()) {
3054 return Promise();
3055 }
3056 return scope.Escape(result).As<Promise>();
3057#endif
3058}
3059
3060inline MaybeOrValue<Promise> Promise::Then(const Function& onFulfilled) const {
3061 return Then(static_cast<napi_value>(onFulfilled));

Callers 1

CatchMethodFunction · 0.80

Calls 8

JustFunction · 0.85
PromiseClass · 0.85
UnwrapToMethod · 0.80
CallMethod · 0.80
IsJustMethod · 0.80
EscapeMethod · 0.80
UnwrapMethod · 0.80
EnvMethod · 0.80

Tested by

no test coverage detected