如何在 firebug 中导致调试中断
我试图在检测到错误时让萤火虫中断。具体来说,我在代码中进行了一些内部检查,例如断言,我希望 Firebug 在失败时停止。我尝试了几种不同的方法,并想知道其他人是怎么做的?以下是我尝试过的方法:
- 放入一些无效代码,以便如果出现错误: 函数断言(值){ if(!值)dbgbreak(); } // 失败,因为 dbgbreak 未定义
这在某种程度上可以工作,但不会以我可以看到堆栈或检查局部变量的方式停止代码。
- 让它抛出异常: 函数断言(值){ 如果!值)抛出 AssertException();这
更漂亮,但当我跟踪异常时,我仍然看不到堆栈或局部变量
- 在断言失败上放置断点。然而,这是可行的,这意味着每次运行代码时我都必须手动放置一堆断点。
其他人在使用调试器和断言以及类似的一致性检查方面做了什么?
I am trying to make firebug break when an error is detected. Specifically, I have some internal checks in my code, like assertions, that I want firebug to stop on when they fail. I have tried a few different ways and wondered what other people do? Here are the ways I have tried:
- Put in some invalid code so that if errors out:
function assert(value) { if(! value) dbgbreak(); } // Fails because dbgbreak not defined
This works somewhat, but does not stop the code in such a way that I can see the stack or examine local variables.
- Have it throw an exeption:
function assert(value) { if ! value) throw AssertExecption(); }
This is prettier, but still when I track exceptions I can't see the stack or the locals
- Put a breakpoint on the assert failure. This works, however, it means everytime I run my code I have to manually put in a bunch of breakpoints.
What do other people do in terms of working with the debugger and asserts, and similar consistency checks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过在脚本中希望其停止的地方扔掉“debugger”关键字?
Have you tried throwing down the "debugger" keyword in your script where you want it to stop?
在控制台选项卡上有一个用于中断所有错误的按钮。打开它,当发生错误时它会自动中断。
http://getfirebug.com/wiki/index.php/Console_Panel#Break_On_All_Errors
On the console tab there is a button for breaking on all errors. Turn that on, and it will automatically break when an error occurs.
http://getfirebug.com/wiki/index.php/Console_Panel#Break_On_All_Errors