tags:

views:

42

answers:

3

I'm using Firebug 1.5.4. When I reference an undefined variable or some such, it breaks right where the problem occurs, and throws me into the debug view where I can see the stack and inspect variables.

However, when I throw my own exception, it just takes me to the console and prints out "uncaught exception: blah". I'd like it to break and let me inspect variables. How can I tell Firebug to do this?

A: 

Put a debugger; statement in your code or use the Script tab of firebug to click on a line number (which inserts a breakpoint).

If you only want to do it when you throw an exception, you could put the debugger statement in a catch block.

thenduks
It is not feasible to use a breakpoint in this case since the exception might not occur until the 100th time through the code, and I don't want to step through it 100 times. I am only interested if/when an exception occurs. But tell me more about this "debugger;" thing...
Kevin Pauli
Ok so when you catch your exception, in the `catch` block, but `debugger;` in there (or insert a breakpoint there in firebug). That way you'll only get dropped into the debugger when the exception happens.
thenduks
In the context of your question the code `debugger;` is simply the same as inserting a breakpoint in firebug on that line.
thenduks
+1  A: 

The respondent was helpful but neglected something very key I was missing; the window.onerror event. Here is the full code:

 window.onerror = function(msg) {
   debugger;
 }
Kevin Pauli
A: 

Install Firebug 1.6b1 http://getfirebug.com/releases/firebug/1.6X, Firebug > Console > "the exception" Click the breakpoint selector in the left column. Run your code. Firebug breaks on that line.

Or Firebug > Console > [||] breaks on next error

johnjbarton