最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why does window.onerror not catch stack overflow errors in IE9? - Stack Overflow

programmeradmin1浏览0评论

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: /

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 ment) 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 ments, Firefox 15 sometimes (seemingly random) seem to swallow that exception as well.

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/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 ment) 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 ments, Firefox 15 sometimes (seemingly random) seem to swallow that exception as well.

Share Improve this question edited Sep 5, 2012 at 12:37 Christofer Eliasson asked Aug 20, 2012 at 19:49 Christofer EliassonChristofer Eliasson 33.9k7 gold badges77 silver badges103 bronze badges 3
  • 3 I really hope this isn't the reason, but it would be kind of hilarious if, since the call stack size was exceeded, IE couldn't call the handler. – Ryan Kinal Commented Aug 20, 2012 at 20:03
  • @RyanKinal LOL, I didn't even think of that. It would be awful if that is the case. – Christofer Eliasson Commented Aug 20, 2012 at 20:08
  • 1 stack error is not thrown on FF 15. Just seeing the ReferenceError: test is not defined. – Selvakumar Arumugam Commented Sep 4, 2012 at 18:58
Add a ment  | 

1 Answer 1

Reset to default 7 +50

Have you tried disabling script debugging on the browser?

A mon problem that bites many developers occurs when their onerror handler is not called because they have script debugging enabled for Internet Explorer. This will be the case by default if you have installed the Microsoft Script Debugger or Microsoft Visual Studio 6.0® (specifically Visual InterDev 6.0™)—onerror handling is how these products launch their debugger.

Source (includes details on how to disable it).


Additional information following up on the ments:

Then I wonder is it related to this:

Internet Explorer 9 is piled with the new C++ piler provided with Visual Studio 2010. This piler includes a feature known as Enhanced GS aka Stack Buffer Overrun Detection, which helps prevent stack buffer overruns by detecting stack corruption and avoiding execution if such corruption is encountered.

(Source)

Sounds like it could be that it is stopping before the overflow as a protection mechanism?

发布评论

评论列表(0)

  1. 暂无评论