Link to home
Start Free TrialLog in
Avatar of Member_2_5069294
Member_2_5069294

asked on

Firebug debugging problems

I'm using Firebug for debugging Javascript in Firefox.  It works well in many ways, but there are a few things I can't get to work.  They both relate to exceptions.

When the script causes an exception, Firebug shows an error message in the console and stops.  However, there is no stack trace and nothing in the watch panel.  The exception happens in a function that is called from many other functions.

I've tried setting Break On All Errors, it makes no difference.  I've set the Show Stack Trace With Errors option, still no difference.  I could use the error message in the console to set a breakpoint on the line that causes the exception, only this stops every time the function is called.  Which means I can't run the script long enough to generate the exception.

This leads to the second problem.  Once I've set a breakpoint from the console, execution always stops at that line but the breakpoint dosen't show in the script view.  I can't find a way to remove it.
Avatar of Sudaraka Wijesinghe
Sudaraka Wijesinghe
Flag of Sri Lanka image

Availability of the stack trace depends on how the exception is generated. For internal JS exception trace is generated almost all the time. But for custom exceptions, you have to throw and Error object in order to get the trace.
throw 'custom error message'; //No stack trace generated

throw new Error('custom error message'); //Stack trace is generated

Open in new window


For your second question, all available break points are listed on the script tab on the right hand side "Breakpoints" panel.
Avatar of Member_2_5069294
Member_2_5069294

ASKER

The line that causes the error is using a 2D context on a Canvas.  It's calling context.drawImage() and supplying negative coordinates for the source, which causes the exception.  I have solved the original bug now, but it has appeared before and is likely to turn up again.  Does the canvas count as a custom exception? Surely it's part of the browser.  I can't see how I can throw an error except unless I wrap any calls to the context in a try-catch structure?

Thanks for answer to the removing the breakpoint part.  It seems obvious now that you've pointed it out.
I'm not familiar with the 2D canvas thing you mentioned, but if it's a 3rd party library, it's possible it's just throwing out text as the exception.

Only way to deal with exceptions gracefully is to catch them in try-catch blocks. However you can throw one from anywhere.
ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the answers.  I guess you're right, Firefox dosen't have proper support for Canvas errors yet.  I've switched to Chrome, which catches the errors perfectly.