Re: Exceptions in event listeners triggered by dispatchEvent().

* John Barton wrote:
>Consider the following code, assuming one of the listeners throws:
>----
>   try {
>     targetElement.dispatchEvent(evt);
>   } catch(exc) {
>     console.log("A listener had a error");
>     return;
>   }
>   goOnToGlory();
>----
>
>How can a developer know that the catch block can never be executed and yet
>exceptions in handlers are reported as uncaught? The only other experience
>that I know about which accounts with these two facts is that
>dispatchEvent() schedules listener executions on another event turn.  But
>it doesn't, it's just another wacko Web behavior we have to look up and
>memorize.

http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget
is where I have learned under which conditions dispatchEvent raises an
exception, on top of the usual reasons, like running out of memory. It
does not mention listeners being terminated by uncaught exceptions and
I would not otherwise expect exceptions to propagate through dispatch-
Event, because one broken listener should not break other listeners so
the exception cannot be allowed to propagate through `dispatchEvent`.
-- 
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 

Received on Tuesday, 4 June 2013 18:22:50 UTC