JavaScript:有没有办法让Chrome打破所有错误? [英] JavaScript: Is there a way to get Chrome to break on all errors?

查看:105
本文介绍了JavaScript:有没有办法让Chrome打破所有错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Chrome中找到相当于破坏所有错误功能的Firebug。在脚本标签中,Chrome具有暂停所有例外,但这与打破所有错误并不完全相同。

I am looking for an equivalent in Chrome to the "break on all errors" functionality of Firebug. In the Scripts tab, Chrome has a "pause on all exceptions", but this is not quite the same as breaking on all errors.

例如,加载页面时使用以下代码,我希望Chrome可以在 foo.bar = 42 行中断。相反,即使启用暂停所有例外,我也没有得到预期的结果。

For instance, when loading a page with the following code, I would like Chrome to break on the line foo.bar = 42. Instead, even when enabling the "Pause on all exceptions", I don't get the expected result.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <script type="text/javascript">

            function doError() {
                foo.bar = 42;
            }

            window.onload = function() {
                try {
                    doError();
                } catch (e) {
                    console.log("Error", e);
                }
            }
        </script>
    </head>
    <body>
    </body>
</html>

您可以尝试上面贴在此页面或使用此 jsFiddle

You can try the code pasted above on this page or using this jsFiddle.

推荐答案

编辑:以下URL不再有效。我保留它是为了不使答案无效,但较新的URL将是 https://developers.google.com/web/tools/chrome-devtools/javascript/add-breakpoints#exceptions 截至2016-11-11。

The URL below is no longer valid. I'm keeping it in order to not invalidate the answer, but the newer URL would be https://developers.google.com/web/tools/chrome-devtools/javascript/add-breakpoints#exceptions as of 2016-11-11.

我意识到这个问题有一个答案,但不再准确。

I realize this question has an answer, but it's no longer accurate.

https://developer.chrome.com/devtools/docs/javascript-debugging#pause-on-exceptions - 您现在可以将其设置为打破所有异常或仅处理未处理的异常。 (请注意,您需要在来源标签中查看按钮。)

https://developer.chrome.com/devtools/docs/javascript-debugging#pause-on-exceptions - you can now set it to break on all exceptions or just unhandled ones. (Note that you need to be in the Sources tab to see the button.)

Chrome还添加了一些其他非常有用的断点功能,例如破坏DOM更改或网络事件。

Chrome's also added some other really useful breakpoint capabilities now, such as breaking on DOM changes or network events.

通常我不会重新回答一个问题,但我自己也有同样的问题,错误的答案,所以我想我会把这些信息放在这里,为后来的人们进行搜索。 :)

Normally I wouldn't re-answer a question, but I had the same question myself, and I found this now-wrong answer, so I figured I'd put this information in here for people who came along later in searching. :)

这篇关于JavaScript:有没有办法让Chrome打破所有错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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