Le 20 déc. 2012 à 00:31, John J Barton <[email protected]> a écrit :

> On Wed, Dec 19, 2012 at 11:23 AM, Brendan Eich <[email protected]> wrote:
>> John J Barton wrote:
>> 
>>> On Wed, Dec 19, 2012 at 8:11 AM, Brandon Benvie <[email protected] 
>>> <mailto:[email protected]>> 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

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to