help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: About `catch' and `throw'


From: Pascal J. Bourguignon
Subject: Re: About `catch' and `throw'
Date: Sat, 22 Dec 2012 21:33:54 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> During the evaluation of code that is lexically inside the `catch',
>> a `throw' that is evaluated throws back to that `catch'.
>
> Usually, but not always.
>
>> And if there is more than one `catch' with the same label then it
>> throws to the one that is lexically nearest (i.e., innermost, outside
>> the `throw'), which is also the most recent.
>
> Usually, but not always:
>
>   (catch 'foo
>     (let ((f (lambda () (throw 'foo))))
>       ...
>       (catch 'foo
>         (funcall f))
>       ...))
>
> will throw to the inner catch, not the outer one.

Again, because it does not matter WHERE the catch is: it's not because
it's _placed_ _inner_ or _outer_.

What matter is WHEN the catch is: it is because it is the most recently
established catch 'foo, that it will catch the throw 'foo.  Conversely
with:

   (catch 'foo
     (funcall (catch 'foo
                 (lambda () (throw 'foo)))))

it is the first catch 'foo which is the most RECENTLY established catch
'foo, WHEN throw 'foo is called, because the second catch 'foo at that
TIME has been already disestablished.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]