Why does window.onerror not catch stack overflow errors in IE9?

Viewed 2140

I'm using window.onerror to catch and log client-side errors. I've read about the various caveats to this approach, but I haven't been able to track down any info on this particular case.

For some reason IE9 does not seem to catch stack overflow exceptions. The below example catches both errors when run in Chrome and Firefox as well as if I use devtools in IE9 and set browser mode to IE8 or IE7. However, when run in IE9 mode, it only catches the 'test' is undefined exception, but ignore the stack overflow exception.

I have put together a simple example, to demonstrate this:

window.onerror = errorHandler;

function errorHandler (msg) {
    alert(msg);        
}

setTimeout(function () {
    test.test = "test";
}, 1000);

setTimeout(function stackoverflow() {
    stackoverflow();
}, 2000);
​

Here is a working example as well: http://jsfiddle.net/Mzvbk/1/

Can anyone shed some light on why this is?

Update August 29, 2012

I posted this question on the Internet Explorer Developer Center as well, but so far it hasn't given me much.

At this point, the best guess (as suggested by @RyanKinal in his comment) is that since the call stack size is exceeded, there is no room to put the call to the error handler on the stack.

I still like to believe that error handling is handled separately from the normal stack, as it seem to be in other browser (even older versions of IE), but if that isn't the case, it would be nice to see a reference, bug-report or statement of some kind, indicating that this actually is the case with IE9.

Update September 5, 2012

As described by Ren and Vega in their comments, Firefox 15 sometimes (seemingly random) seem to swallow that exception as well.

1 Answers
Related