Re: Throwing an error in an event listener

On 10/27/12 11:04 AM, David Bruant wrote:
> Ms2ger directed me to https://www.w3.org/Bugs/Public/show_bug.cgi?id=17713
> Second issue is what is expected from window.onerror. In the bug, Ms2ger
> said:
> " Gecko doesn't trigger window.onerror; Chrome, Opera-next and IE10 do."

It depends.

In this testcase:

   <div onclick="throw 'Inline'">Click me</div>
   <script>
     window.onerror = function(file, line, text) {
       alert(file + " " + line + " " + text);
     }
     document.querySelector("div").addEventListener("click", function() {
       throw "Added";
     });
   </script>

Gecko triggers onerror for both exceptions.

Gecko does have a bug in terms of calling window.onerror (and reporting 
to its own error console, since that uses the same mechanism) when a 
listener added via addEventListener is triggered due to an event that's 
dispatched while page script is running (e.g. if you do a manual 
dispatchEvent()).  But it's just a bug that needs fixing.

> I'll go with the assumption that the error should trigger an error event
> on window for now

Yes.

-Boris

Received on Saturday, 27 October 2012 16:53:19 UTC