napi_get_last_error_info


napi_status
napi_get_last_error_info(node_api_basic_env env,
                         const napi_extended_error_info** result); 
  • [in] env:调用该 API 时所处的环境。
  • [out] result:包含有关错误的更多信息的 napi_extended_error_info 结构。

如果 API 成功,则返回 napi_ok

【Returns napi_ok if the API succeeded.】

此 API 会检索一个包含最近发生错误信息的 napi_extended_error_info 结构。

【This API retrieves a napi_extended_error_info structure with information about the last error that occurred.】

napi_extended_error_info 返回的内容仅在对同一个 env 调用 Node-API 函数之前有效。这包括 napi_is_exception_pending 的调用,因此通常需要复制信息以便稍后使用。返回的 error_message 指针指向一个静态定义的字符串,因此,如果你在调用另一个 Node-API 函数之前已经将其从 error_message 字段中复制出来(该字段会被覆盖),使用该指针是安全的。

【The content of the napi_extended_error_info returned is only valid up until a Node-API function is called on the same env. This includes a call to napi_is_exception_pending so it may often be necessary to make a copy of the information so that it can be used later. The pointer returned in error_message points to a statically-defined string so it is safe to use that pointer if you have copied it out of the error_message field (which will be overwritten) before another Node-API function was called.】

不要依赖任何扩展信息的内容或格式,因为它不受语义化版本控制(SemVer)约束,可能随时发生变化。它仅用于记录目的。

【Do not rely on the content or format of any of the extended information as it is not subject to SemVer and may change at any time. It is intended only for logging purposes.】

即使存在挂起的 JavaScript 异常,也可以调用此 API。

【This API can be called even if there is a pending JavaScript exception.】