[BUG] Exception handling #ensure: and #return:

Raab, Andreas Andreas.Raab at disney.com
Sun Mar 4 23:38:15 UTC 2001


Folks,

We just found out (the hard way of course) that there is a serious problem
in exception handling. It appears that using #return: deeply in a stack
that's protected somewhere on top by #ensure: will lead to some rather weird
effects. Here's a short example:

Object>>testMethod
	^[self primitiveFailed. true] on: Error do:[:ex| ex return: false].

Object>>runTestMethod
	| vv |
	[
		vv _ self testMethod.
		vv
			ifTrue:[Transcript cr; show:'vv is true']
			ifFalse:[Transcript cr; show: 'vv is false'].
	] ensure: [ Transcript cr; show: 'Done with it'].

Obviously the transcript should say "vv is false" and then "done with it".
But if you try it, you'll see that it prints *nothing* at all.

Looking closer, it seems that the handling of ExceptionAboutToReturn in
BlockContext>>valueUninterruptibly is broken. It never checks if the context
we're returning to is actually above that handler context so that whenever
we #return we will do some weird stuff on the stack which is not affected at
all by the return.

Attached is a CS that attempts to fix the problem. Since I don't have a very
deep understanding about the EH stuff I'd appreciate it if somebody with a
deeper understanding could have a look at it and say it's okay or fix
whatever needs to be fixed.

Thanks,
  - Andreas

-------------- next part --------------
A non-text attachment was scrubbed...
Name: EnsureFix-ar.1.cs
Type: application/octet-stream
Size: 2340 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20010304/e05cad81/EnsureFix-ar.1.obj


More information about the Squeak-dev mailing list