Conditional catch clause

Claude Pache claude.pache at gmail.com
Wed Dec 19 16:39:54 PST 2012


Le 20 déc. 2012 à 00:31, John J Barton <johnjbarton at johnjbarton.com> a écrit :

> On Wed, Dec 19, 2012 at 11:23 AM, Brendan Eich <brendan at mozilla.com> wrote:
>> John J Barton wrote:
>> 
>>> On Wed, Dec 19, 2012 at 8:11 AM, Brandon Benvie <brandon at brandonbenvie.com <mailto:brandon at brandonbenvie.com>> wrote:
>>> 
>>>     The magical quality that throw has is its ability to end multiple
>>>     call frames at once. Much like a second continuation channel, or
>>>     the error channel in a promise, it escapes past any number of
>>>     listeners on the normal channel, only stopping at the first
>>>     listener on the error channel.
>>> 
>>> 
>>> Well said: it's always possible to argue for 'goto' in specific cases. With experience we've learned that these seemingly sensible features have debilitating system effects.
>> 
>> Which sensible features do you mean? Termination-style exception handling, meaning 'throw'?
> 
> goto, and similar control transfers. 'throw' has proven to be a useful exception ... because we use it for exceptions.

With goto, you need (1) to know where to go, and (2) to pick a label name and put it at two possibly distant places. With throw/catch, you don't; therefore I think that throw/catch is superior (where it is possible to replace goto by throw/catch, which I think is most of the time).

Throw/catch is useful for exceptions, it doesn't mean that such a mechanism could not have other legitimate uses. I think that we are not accustomed to use it for anything else than exceptions in everyday code, because we don't often need it and we generally find a workaround. StopIteration is IMHO a nice example of a good use of throwing a non-error: The iterator is asked for the next value, but there is none, so it throws (but it is not an error), and the execution resume where it should (e.g. after a for/of loop or at some place manually identified by a catch clause), without the need to add some branching statement at every place the iterator is invoked.

Claude

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121220/3f233d32/attachment-0001.html>


More information about the es-discuss mailing list