[BUG?] Strange behavior of exceptions and ensure:
Nathanael Schärli
n.schaerli at gmx.net
Thu May 18 00:39:34 UTC 2000
Hi Squeakers
Yesterday, I noticed a very strange behavior of the Squeak exception
mechanism.
The following example illustrates this (The code is also in the attached
fileout).
Create the new class StrangeExample and add the following methods:
StrangeExample class>>methodA1
Transcript cr.
self methodB.
Transcript show: 'Finished1 '.
StrangeExample class>>methodB
[self error: 'ErrorMsg ']
on: Error do:
[:ex |
Transcript show: 'ErrorHandling '.
ex return: 5].
Transcript show: 'Finished2 '.
Now it's getting interesting. Open a workspace and type the code:
StrangeExample methodA
Now select this code and use the shortcut cmd-d for 'do it'.
As expected the Transcript output is:
'ErrorHandling Finished2 Finished1'
Now select the code again and use the mouse to select 'do it' in the
context menu. Surprisingly the output in the Transcript is now:
'ErrorHandling Finished2'
(I got this result with a current 2.8a image. Surprisingly I got the
correct result using a default 2.7 image. However, the second part of the example
(described below) shows a strange behavior using either of these images and
thus this seems not to be a simple update bug).
Why is the result different? After some debugging, I saw that the problem
is the method BlockContext>>ensure: resp.
BlockContext>>valueUninterruptably. If 'do it' is called via the mouse, the whole code is executed inside an
ensure:, but when it is called via shortcut the code is executed without a
call of ensure:.
To verify this, I wrote the following method:
StrangeExample class>>methodA2
Transcript cr.
[self methodB]
ensure: [Transcript show: 'Ensure1 '].
Transcript show: 'Finished1 '
As expected, the output on the Transcript is
'ErrorHandling Finished2', and this independent wheter I started it via
mouse or shortcut and also independent of the image version.
It seems to me that execution stops when an exception occurse inside an
ensure: resp. valueUninteruptably.
Although I'm (up to a certain extent) familiar with the BlockContext and
Exception implementations, it would take me some time to look at it closely.
Therefore my question to the community: Can you confirm this behavior? Is
it a bug? If yes, does anyone have a fix?
Thanks
Nathanael
--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nathanael Schaerli
Ruettenenstrasse 41
CH-4515 Oberdorf, Switzerland
Phone: +41 32 622 89 03
Fax: +41 32 621 78 50
Email: n.schaerli at gmx.net
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
-------------- next part --------------
Object subclass: #StrangeExample
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'StrangeExceptions'!
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
StrangeExample class
instanceVariableNames: ''!
!StrangeExample class methodsFor: 'example' stamp: 'NS 5/16/2000 11:33'!
methodA1
Transcript cr.
self methodB.
Transcript show: 'Finished1 '.! !
!StrangeExample class methodsFor: 'example' stamp: 'NS 5/16/2000 11:33'!
methodA2
Transcript cr.
[self methodB]
ensure: [Transcript show: 'Ensure1 '].
Transcript show: 'Finished1 '! !
!StrangeExample class methodsFor: 'example' stamp: 'NS 5/16/2000 11:37'!
methodB
[self error: 'ErrorMsg ']
on: Error do:
[:ex |
Transcript show: 'ErrorHandling '.
ex return: 5].
Transcript show: 'Finished2 '! !
More information about the Squeak-dev
mailing list
|