Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I put an end to quiet deaths of JavaScript functions? (Does setTimeout swallow exceptions?)

Every now and then some JavaScript function I'm working on would just quit quietly, without anything indicating in any way that something out of the ordinary has occurred.

This is driving me insane. Surely there must be a way to turn on some sort of "I'm a developer" flag so that things like this will throw a big fat "Something's Wrong!" message?

Example function:

window.setTimeout(function() {
    alert('Entered!');
    foo;
    alert('Exited!');
}, 300);

On my Firefox 6, this shows only the first alert. The Error Log remains completely empty. Can I get a more useful behaviour out of Firefox?

like image 793
Roman Starkov Avatar asked Sep 12 '11 11:09

Roman Starkov


2 Answers

You could try using a try -> catch around bits of the code to see what crashes?

Take a look at this link: http://www.w3schools.com/js/js_try_catch.asp

For example; you can have an alert pop up with the error description.

like image 38
Frank Allenby Avatar answered Oct 22 '22 18:10

Frank Allenby


I suspect that the issue might be this one: https://developer.mozilla.org/en/Exception_logging_in_JavaScript. The new logic that decides which exceptions need to be displayed does have some flaws (particularly when extensions are involved).

You can go to about:config and create a boolean preference dom.report_all_js_exceptions. This will make sure that a whole lot more exceptions will show up in Error Console - probably more than you would like to see.

Edit: There is also an issue that causes Adblock Plus to swallow some errors: bug 653533. I'm not sure whether it is covered by the pref I mentioned above.

like image 66
Wladimir Palant Avatar answered Oct 22 '22 19:10

Wladimir Palant