ExtJS中的全局错误处理

时间:2013-07-26 18:40:44

标签: javascript extjs

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

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

1 个答案:

答案 0 :(得分: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