finalisation

Jesse Welton jwelton at pacific.mps.ohio-state.edu
Wed Jan 28 19:22:28 UTC 2004


Andreas Raab wrote:
> 
> > Does this not catch all the possibilities ?
> 
> No, of course not. That's why I find the style of putting the resource
> creation inside the ensured block so terribly misleading. It puts you under
> the impression that you caught all the possibilities, where it is easy to
> see from an example like
> 
>     [file := (FileStream newFileNamed: 'foo.bar') halt.
>     ] ensure:[file close].
> 
> that you do not catch anything that happens on the right hand side of the
> assignment. IOW, execute the above and close the resulting debugger - it
> will end up with a DNU for file close which illustrates that - although the
> file has been created - it is not being cleaned up after encountering the
> halt.

Andreas, you correctly point out that this failure mode cannot be
caught and handled.  If I understood Craig, the failure mode he was
referring to would be simulated by

    (file := (FileStream newFileNamed: 'foo.bar')) halt.
    [ file doStuff ] ensure: [ file close ].

Here, the failure can be caught by moving the file creation into the
block.  You argue that this is statistically unlikely, but as Craig
and Richard point out, this kind of thing can and does happen
occasionally.  So, while moving the creation code into the block
cannot catch all possible failure modes, it can catch a failure mode
which having the creation outside the block cannot, albeit a rare one.
The cost for this is having to be able to cope with a nil file
variable in the ensure block, in case of the more likely failure mode
you mention.  Apparently, the two sides in this argument differ in the
weight they give to each of these factors.

-Jesse



More information about the Squeak-dev mailing list