Exceptions in event listeners triggered by dispatchEvent().

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.

I was surprised by the behavior in Chrome and reported:
https://code.google.com/p/chromium/issues/detail?id=239648
The little test case is online:
http://johnjbarton.github.io/webdev-examples/239648_TryCatchFails/uncaughtErrors.html

Thanks,
jjb

Received on Sunday, 2 June 2013 17:20:44 UTC