Fixing up state after error
Ned Konz
ned at bike-nomad.com
Tue Aug 19 21:21:31 UTC 2003
On Tuesday 19 August 2003 11:56 am, Joshua 'Schwa' Gargus wrote:
> Hi,
>
> I'm pretty sure that that there's a way do what I want, but I can't
> find it.
>
> Here's a simplified version of my problem: I have an object that
> wants to save itself on a ReferenceStream in response to
> #writeToFile, but it has some property stored in an instVar named
> 'prop' that I don't want stored (I later store it separately).
>
> I have something like:
>
> writeToFile
>
> | propHolder |
>
> ref := ReferenceStream on: (FileStream fileNamed: 'output.obj').
> propHolder := prop.
> prop := nil.
> ref nextPut: self.
> prop := propHolder
>
>
> I want to assure that if something goes wrong during stream
> writing, and triggers a walkback, that 'prop' gets restored to its
> old value. I'm pretty sure I saw somthing like this recently in
> the image, but can't remember where.
Why not just:
propHolder := prop.
prop := nil.
[ ref nextPut: self ] ensure: [ prop := propHolder ]
--
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE
More information about the Squeak-dev
mailing list
|