469,625 Members | 1,775 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

FireFox: addEventListener Vs. window.onerror

Hi,

I've been using window.onerror to capture and report JavaScript errors
from other users for debugging an application I've written. But I've
run into a strange issue with Firefox and window.onerror.

It seems that any code that executes, having originated from an
"element.addEventListener", causing an error does not activate
"window.onerror". But it does at least show up in Firefox's JavaScript
error console. Internet Explorer doesn't appear to suffer from the
same issue when it uses it's equivalent "element.attachEvent".

Does anyone know why this is and if there is any workarounds or if it's
possibly a bug?

Code Example:
var ErrorHandler = function(msg, url, line) {
alert(msg+': '+url+': '+line);
};
window.onerror = ErrorHandler;

var Func = function(e) {
// The following line should cause an error since the variables don't
exist
noSuchVar = imagination.figment;
};

window.onload = function(e) {
// This activates window.onerror when "test1" is clicked
document.getElementById('test1').onclick = Func;
// In FF, this does not activate window.onerror when "test2" is
clicked
document.getElementById('test2').addEventListener( 'click', Func,
false);
};

Nov 30 '06 #1
2 13262

cr*******@youmuppet.com wrote:
Hi,

I've been using window.onerror to capture and report JavaScript errors
from other users for debugging an application I've written. But I've
run into a strange issue with Firefox and window.onerror.

It seems that any code that executes, having originated from an
"element.addEventListener", causing an error does not activate
"window.onerror". But it does at least show up in Firefox's JavaScript
error console. Internet Explorer doesn't appear to suffer from the
same issue when it uses it's equivalent "element.attachEvent".

Does anyone know why this is and if there is any workarounds or if it's
possibly a bug?
onerror isn't part of any specification, so its behaviour is
essentially undefined. Nor is there anything to specify how or when it
should be called, so you really can't call this a bug unless you have
something to show that it's contrary to the intended behaviour.

Your test example doesn't "work" at all in Safari or Opera.
--
Fred

Nov 30 '06 #2

Fred wrote:
onerror isn't part of any specification, so its behaviour is
essentially undefined. Nor is there anything to specify how or when it
should be called, so you really can't call this a bug unless you have
something to show that it's contrary to the intended behaviour.

Your test example doesn't "work" at all in Safari or Opera.
True, I missed the fact that it's not part of the specs but it appears
to behave similar across the platforms I'm most concerned with. I
don't like cutting out Safari and Opera but since it's an internal
application I know that the only clients being used are Firefox and IE,
but thanks for the info as I'd probably run into those browsers sooner
or later ;-)

Guess I'll just have to write more try catches in my code by the looks
of things.

Dec 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by jimmygoogle | last post: by
10 posts views Thread by Paul Gorodyansky | last post: by
7 posts views Thread by Coder | last post: by
8 posts views Thread by Sunny | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.