FireFox: addEventListener Vs. window.onerror

C

crazydave

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);
};
 
F

Fred

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.
 
C

crazydave

Fred said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top