W3C home > Mailing lists > Public > public-script-coord@w3.org > April to June 2013

Re: Catching exceptions

From: Allen Wirfs-Brock <allen@wirfs-brock.com>
Date: Tue, 2 Apr 2013 08:49:29 -0700
Cc: "public-script-coord@w3.org" <public-script-coord@w3.org>
Message-Id: <9C211901-BCCF-45F0-8B36-E2C6CD19D19A@wirfs-brock.com>
To: Anne van Kesteren <annevk@annevk.nl>
The ECAMScript specification uses Completion types http://ecma-international.org/ecma-262/5.1/#sec-8.9 to propagate and handle exceptions. In ES5, all statement level constructs of the language return completion values and in some cases they explicitly check the completion values returned from nested code.  For example see http://ecma-international.org/ecma-262/5.1/#sec-12.10 step 7.  

Also see the last paragraph of http://ecma-international.org/ecma-262/5.1/#sec-5.2 . This is how the ES5 spec. deals with built-in functions that call other functions that might throw.  they just assume that the exception is propagated until it is handled by something like the with statement referenced above.

The ES5 approach is rather sloppy and leaves too much room for implementations to have observable variation in their recognition of unexpected exceptions.

The ES6 spec is more explicit about exception handling.  It has an expanded definition of the Completion type http://people.mozilla.org/~jorendorff/es6-draft.html#sec-8.2.3 and expands to the use of Completion values to all types of evaluation, not just at the statement level. It also requires all algorithms to explicitly state their handling of propagated exceptions.  See for example the ES6 definition of Array forEach http://people.mozilla.org/~jorendorff/es6-draft.html#sec- and compare it to the ES5 definition http://ecma-international.org/ecma-262/5.1/#sec-  

On Apr 2, 2013, at 2:38 AM, Anne van Kesteren wrote:

> So reading the ECMAScript specification I cannot find this concept
> used there. A number of scenarios require us to catch exceptions and
> either handle them or maybe re-throw them as appropriate. Is this
> language fine:
> 1. Invoke /callback/ ...
> 2. If that threw an exception, ...
> Or are there some other things I need to take into account? Is there
> preferred language for this kind of pattern?
> --
> http://annevankesteren.nl/

Received on Tuesday, 2 April 2013 15:50:07 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:12 UTC