Capturing non-local returns?

Anthony Hannan ajh18 at cornell.edu
Sat May 24 18:13:47 UTC 2003


Avi Bryant <avi at beta4.com> wrote:
> On Sat, 24 May 2003, Andreas Raab wrote:
> > I was wondering if there's a good way of capturing non-local returns and
> > ONLY non-local returns from some block. E.g., the problem I'm having is that
> > I am evaluating a block and if (and ONLY if) it attempts to do a non-local
> > return I want to capture the return and take some appropriate action.
> Will this not work?
> 
> |normalReturn|
> normalReturn := false.
> [aBlock value.
>  normalReturn := true]
>    ensure: [normalReturn ifFalse: [...]]

I believe this is equivalent to:

aBlock ifCurtailed: [...]

[...] will only get executed if aBlock does a non-local return. 
#ifCurtailed: has been refactored in ContextCleanupPlus-ajh to make this
efficient, and correct if this is not working correctly for you in the
current image.

>> It seems that neither #ifCurtailed: nor #ensure helps much since the first
>> will be evaluated upon 'abnormal termination' (and that's not my problem
>> as the termination is perfectly reasonable - just attempting to bypass some
>> important action).

I'm not sure what you mean by 'abnormal termination'.  I view
termination as process termination which is just an extreme non-local
return.  Termination (which should always include unwind) returns all
the way back to the first context of the process.  #ifCurtailed: (as
well as the Avi's example above) will catch this as well and execute its
before continuing the termination.

Cheers,
Anthony



More information about the Squeak-dev mailing list