JS_ReportErrorNumber 编辑
Report an error with an application-defined error code.
Syntax
void
JS_ReportErrorNumber(JSContext *cx, JSErrorCallback errorCallback,
void *userRef, const unsigned errorNumber, ...);
void
JS_ReportErrorNumberUC(JSContext *cx, JSErrorCallback errorCallback,
void *userRef, const unsigned errorNumber, ...);
bool
JS_ReportErrorFlagsAndNumber(JSContext *cx, unsigned flags,
JSErrorCallback errorCallback, void *userRef,
const unsigned errorNumber, ...);
bool
JS_ReportErrorFlagsAndNumberUC(JSContext *cx, unsigned flags,
JSErrorCallback errorCallback, void *userRef,
const unsigned errorNumber, ...);
void
JS_ReportErrorNumberUCArray(JSContext *cx, JSErrorCallback errorCallback,
void *userRef, const unsigned errorNumber,
const char16_t **args); // Added in SpiderMonkey 19
Name | Type | Description |
---|---|---|
cx | JSContext * | The context in which to report the error. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext . |
flags | unsigned | Error report flags. |
errorCallback | JSErrorCallback | Callback to fetch the error message. |
userRef | void * | A pointer to application data. The JavaScript engine passes this pointer to errorCallback . The meaning of the data is up to the application. |
errorNumber | const unsigned | An error code. The JavaScript engine passes this number to errorCallback . The meaning of the error number is up to the application. |
... / args | ... / const char16_t ** | Additional arguments for the error message. These arguments must be of type The number of additional arguments required depends on the error message, which is determined by the |
Callback syntax
typedef const JSErrorFormatString * (* JSErrorCallback)(void *userRef, const unsigned errorNumber);
Name | Type | Description |
---|---|---|
userRef | void * | The userRef pointer that was passed to the ReportErrorNumber API. |
errorNumber | const unsigned | The errorNumber that was passed to the ReportErrorNumber API. |
Description
These functions create a JSErrorReport
, populate it with an error message obtained from the given JSErrorCallback
, and either report it to the current error reporter callback or create an Error
object and set it as the pending exception.
First errorCallback(userRef, errorNumber)
is called. If errorCallback
returns NULL
, (??? what happens?).
Otherwise, if the JSErrorFormatString
returned by the JSErrorCallback
has .exnType == JSEXN_NONE
, then the error reporter, if any, is called, and no Error
object is created. (??? The source code seems to say we ignore the .exnType
, actually, but surely I'm just missing something.)
Otherwise, if any JavaScript code is running in cx
(for example, if the caller is a JSNative
that was called from a script), then an Error
object is created and becomes the pending exception. The error reporter is not called yet, because the script still has an opportunity to catch and handle the exception.
Otherwise, no JavaScript code is running in cx
. If the JSOPTION_DONT_REPORT_UNCAUGHT
option is set, (??? what happens?). Otherwise, (??? what happens?).
See Also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论