javascript – ExtJS中的全局错误处理

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

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

解决方法:

看到

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

Globally handle any Ext errors that may be raised, optionally
providing custom logic to handle different errors individually. Return
true from the function to bypass throwing the error to the browser,
otherwise the error will be thrown and execution will halt.

用法示例:

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐