Squeak SmalltalkJoker Squeak Smalltalk : System : prevnext If Curtailed

> > [1/0] ifCurtailed: [self halt].
> >
> > does not halt even if we push the 'abandon' button.
> > (It was his original test code, anyway).

> [1/0] ifCurtailed: [Transcript show: 'exception']
> doesn't work on Squeak 3.6-#5429, I guess.
> Is there anything wrong?

No.
The debugger halts the process while the ifCurtailed: context is still
on the stack, so the ifCurtailed: context hasn't been popped yet
(curtailed or simply returned).  Furthermore, ifCurtailed: only
executes its argument if its context is curtailed (skipped over
because of remote return).  When you hit proceed on the debugger you
are resuming through the error (not remote returning) so the
ifCurtailed: context is not curtailed and hence its argument is not
executed.  If hit abandon on the debugger you are remote returning to
the bottom of the stack (ending the process) so the ifCurtailed:
context is curtailed and hence its argument is executed.  If you
change ifCurtailed: to ensure: you will see that its argument is
always executed whether curtailed or simply returned.
If you catch the error and you do a return in your handler (which is a
remote return to the on:do: caller) then the ifCurtailed: context will
be curtailed and you will see its argument executed.  If you do a
resume in your handler you will resume where the error happened just
like hitting proceed on the debugger and the ifCurtailed: context will
not be curtailed.  Check out the following examples:
[[1/0] ifCurtailed: [Transcript show: ' exception1']] on: Error do:
[:ex | ex return].
[[1/0] ifCurtailed: [Transcript show: ' exception2']] on: Error do:
[:ex | ex resume].
[[1/0] ensure: [Transcript show: ' exception3']] on: Error do: [:ex |
ex resume].
Transcript will print exception1 and exception3.
Cheers,
Anthony

I think most people get confused here because they don't keep in mind
that when you see a notifier, you always have the option to "proceed".
What it means is that when you see the notifier the guarded block
clearly is not terminated ... yet. It's only when you hit the
"abandon" button or close the notifier that the system knows "ah, okay
you want to kill it" and it is only then that the termination handler
is being run.
Cheers,
  - Andreas

Well, I find ifCurtailed: difficult to understand myself,
and I feel that "doesn't work" does not tell what you
expect.
When you evaluate the statement above, you get
an error notifier. When you choose 'abandon' that
notifier closes and the string 'exception' is written
into the Transcript. I tried this also with  VisualWorks,
Dolphin and Smalltalk/X and it is the same everywhere.
Perhaps you were not pleased to see the error notifier.
Then you should use
 [1/0] ifError: [Transcript show: 'exception'].
You may also try this:
[[1/0] ifCurtailed: [Transcript show: 'exception']
   ] on: ZeroDivide
     do: [:exception | exception return: nil].
Here you have a handler that caches the exception.
You will therefore not see a notifier, but the message
is written into the transcript because you jump out of
the block. I think this is the intended use.
ifCurtailed: is a kind of clean up during a jump. The
example above can be easily modified to close files
or communication lines.
> Is there anything wrong?
I think not, but I would really be happy to see an
understandable explanation of  ifCurtailed.
Hope this helps, Boris

> [1/0] ifCurtailed: [self halt].
>
> does not halt even if we push the 'abandon' button.
> (It was his original test code, anyway).
Just for info:
I tested this in 3.2 and 3.4 - works there. Abandon gives the "self
halt" notifier.
Does not work in 3.7-5763. No halt encountered after Abandon.
regards, Göran