W3C home > Mailing lists > Public > www-dom@w3.org > April to June 2013

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

From: Glenn Maynard <glenn@zewt.org>
Date: Sun, 2 Jun 2013 13:10:35 -0500
Message-ID: <CABirCh_a-RkzN9S+qSaAR-ttHxOzZkiAO+Qdn=RQ70x4Kyandg@mail.gmail.com>
To: johnjbarton <johnjbarton@chromium.org>
Cc: "www-dom@w3.org" <www-dom@w3.org>, Anne van Kesteren <annevk@annevk.nl>
On Fri, May 31, 2013 at 3:28 PM, johnjbarton <johnjbarton@chromium.org>wrote:

> When JS calls EventTarget dispatchEvent(evt), EventListener-s are called.
> If those EventListeners throw exceptions, what should happen if the closest
> enclosing try/catch block surrounds the dispatchEvent() call?
> Both Chrome and Firefox currently ignore the try/catch block and report
> that the exception is "uncaught". In Chrome, this EventListener is invoked
> within an internal try/catch (V8::TryCatch) and any exceptions that result
> are reported as uncaught before returning to the caller (eventually
> returning to the caller of dispatchEvent()).
> I could not find any mention in
> http://www.w3.org/TR/DOM-Level-2-Events/events.html of the expected
> result.

This behavior is intentional.  Note that the spec you're reading is over a
decade old, the spec you want is http://dom.spec.whatwg.org.  Specifically,
see http://dom.spec.whatwg.org/#dispatching-events.

I think exceptions from callbacks are handled explicitly in specs, eg. by
saying something like "if the called function throws an exception, ...".
Since the "invoke the event listeners" algorithm (step 4.7) doesn't say to
do anything with exceptions, that means that nothing must be done with
them, eg. discard them.  (Anne: correct?)  Maybe this could use a note,

Glenn Maynard
Received on Sunday, 2 June 2013 18:11:13 UTC

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