JS_IsExceptionPending 编辑
Determine whether an exception is pending in the JS engine.
Syntax
bool
JS_IsExceptionPending(JSContext *cx);
Name | Type | Description |
---|---|---|
cx | JSContext * | Pointer to a JS context to check for pending exceptions. |
Description
JS_IsExceptionPending
returns true
if an exception has been thrown in the context cx
and the exception has not yet been caught or cleared. Otherwise, it returns false
This can be used from JSNative
functions which call JS code to determine if the called JS code threw an exception or not.
Example
/* JSAPI */
bool pending;
JS::RootedValue exception(cx);
/* If an exception is pending, save and clear it. */
pending = JS_IsExceptionPending(cx);
if (pending) {
if (!JS_GetPendingException(cx, &exception))
return false;
JS_ClearPendingException(cx);
}
/* ... code that might throw JS exception ... */
if (JS_IsExceptionPending(cx)) {
/* ... react to exception thrown in this block ... */
JS_ClearPendingException(cx);
}
/* Restore the original exception. */
if (pending) {
JS_SetPendingException(cx, exception);
}
See Also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论