Chrome:从开发控制台调用的代码中是否有错误触发window.onerror? [英] Chrome: Will an error in code invoked from the dev console trigger window.onerror?

查看:493
本文介绍了Chrome:从开发控制台调用的代码中是否有错误触发window.onerror?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图调试我们对window.onerror的处理。我创建了一个会抛出错误的函数(调用另一个不存在的函数)。我试过从Chrome的Web开发控制台调用这个第一个函数 - 在控制台中报告错误,但我们的window.error处理函数似乎没有被调用。 (我已经验证了window.onerror在控制台中引用了我们的错误处理代码)。

I'm trying to debug our handling of window.onerror. I've created a function that will throw an error (invoking another function that does not exist). I've tried calling this first function from Chrome's web development console - an error is reported in the console, but our window.error handling function does not seem to be called. (I've verified that window.onerror references our error handling code in the console).

在dev控制台中调用的函数内的错误不是触发器窗口。 onerror?

推荐答案

p>

They don't (in Chrome where I tested), easy way to test is

window.onerror = function () {console.log('error!');};
throw new Error();
// Error

如果你推迟它们, p>

You can make them do it if you defer them, though

window.setTimeout(function() {throw new Error()}, 0);
// error!
// Uncaught Error

这篇关于Chrome:从开发控制台调用的代码中是否有错误触发window.onerror?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆