W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2012

Throwing an error in an event listener

From: David Bruant <bruant.d@gmail.com>
Date: Sat, 27 Oct 2012 16:13:42 +0200
Message-ID: <CAHbscB2yZY4a1Js1R+_p88s0VXGEeK35Zgg6Sf8VAOgp37+r0A@mail.gmail.com>
To: www-dom@w3.org

Live from Test the web forward in Paris. Here is a test case I've just
written (don't bother):

        var element = document.getElementById('bim');
        var secondCalled = false;

        element.addEventListener('click', function(){
            throw new Error('Error from listener');
        element.addEventListener('click', function(){ secondCalled = true;
}, false);


It's unclear what's the expected behavior in the spec.
The dispatch algorithm says:
(Step 8) Invoke the event listeners of event's target attribute value with
Then, the invoke algorithm says:
(Step 4.7) Call listener's callback, with the event passed to this
algorithm as the first argument.

But nothing is said about what happens if during this call an error is
thrown. In browsers I have tested (Firefox 18, Opera 12, latest Chrome),
the error is absorbed and the next listener is called (so the test
I think the invoke algorithm should make a mention of that somewhere.

Received on Saturday, 27 October 2012 14:14:09 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:37:01 UTC