4

有没有办法全局处理 ExtJS 应用程序中的所有 JavaScript 错误和异常,并将其路由到向用户发出服务器错误警报的函数?

window:onerror()似乎没有处理所有的 JavaScript 错误,因此在代码中寻找某种捕获,将其包装到更通用的异常中以便被捕获?

4

1 回答 1

3

http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.Error-static-method-handle

全局处理可能引发的任何 Ext 错误,可选择提供自定义逻辑来单独处理不同的错误。从函数中返回 true 以绕过向浏览器抛出错误,否则将抛出错误并停止执行。

示例用法:

Ext.Error.handle = function(err) {
    if (err.someProperty == 'NotReallyAnError') {
        // maybe log something to the application here if applicable
        return true;
    }
    // any non-true return value (including none) will cause the error to be thrown
}

通常,onerror 会处理错误,但在 Ext.Error.handle 中返回 true 会阻止这种情况。

另请查看http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.Ajax-event-requestexception

于 2013-07-26T19:30:03.063 回答