Are thrown errors in a try block considered to be handled even if there's no catch block?

Boris Zbarsky bzbarsky at
Fri Jun 23 16:39:40 UTC 2017

On 6/23/17 7:01 AM, T.J. Crowder wrote:
> On Firefox, I get
> ```
> 1
> 2; cancelling
> dispatch complete
> then
> uncaught exception: 1
> uncaught exception: 2
> ```
> ...where the traces point to the `dispatchEvent` line. So it seems to
> store them up and then report them.

I should note that if you add this to your testcase:

   window.onerror = function(...args) {

then you will see something like this in Firefox:

uncaught exception: 1 foo.html 20 1 1
2; cancelling
uncaught exception: 2 foo.html 20 1 2
dispatch complete
uncaught exception: 1
uncaught exception: 2

where those first two "uncaught exception" lines are the logs from the 
error handler.  So for the parts that are web-observable, Firefox does 
the error reporting synchronously.

The rest of what you see is because the console API and the internal 
error reporting use slightly different mechanisms for notifying about 
new messages: the former does it immediately and the latter does it 
after an event loop turn, because it's working with a threadsafe logging 
facility that always handles things via a job queued on the main event loop.

> Replicating the Firefox behavior in your own `dispatchEvent` function is
> fairly doable: Catch the exceptions, store them, and then fire them off
> asynchronously when done (

That won't give you the right onerror behavior.


More information about the es-discuss mailing list