[Q] What is the reason for raise one error trying to save a new file ?

Lic. Edgar J. De Cleene edgardec2001 at yahoo.com.ar
Fri Nov 5 10:14:15 UTC 2004


On 04/11/04 13:13, "Doug Way" <dway at mailcan.com> wrote:

> 
> On Thu, 4 Nov 2004 06:48:11 -0800, "Ned Konz" <ned at squeakland.org> said:
>> On Thursday 04 November 2004 5:15 am, Lic. Edgar J. De Cleene wrote:
>>> I copy from image and this code perhaps belongs to Tim Rowledge .
>>> I not could figure why you choose raise one error if file do not exist.
>>> It¹s not what we wish to do using this method ?
>> 
>> Because the exception is only raised after we have tried once to create
>> the file and failed.
> 
> Yes, it's easy to miss the "self new" in there, which tries to create a
> new file.  (I missed it at first glance.)  Probably that first comment
> should say "Failed to open the newly created file" instead, to be more
> clear.
> 
> - Doug
> 
Thanks Doug and Ned.
And apologies to Tim.
This code failed attempt to create a compressed file using:

localDiskSave
| zip baseDir |
baseDir := ServerDirectory localSqueakBooksDirectory,FileDirectory slash.
zip := ZipArchive new.
self allCards do: [ :each |
    zip addMember: ((ZipStringMember newFrom:  each text
                        named: each title)
                        desiredCompressionMethod: ZipArchive
compressionDeflated;
                        yourself)
    
    ].
zip writeToFileNamed: baseDir, (self getStackNamefromUser) , '.shc'

Where writeToFileNamed in turn use

writeToFileNamed: aFileName
    | stream |
    "Catch attempts to overwrite existing zip file"
    (self canWriteToFileNamed: aFileName)
        ifFalse: [ ^self error: (aFileName, ' is needed by one or more
members in this archive') ].
    stream := StandardFileStream forceNewFileNamed: aFileName.
    self writeTo: stream.
    stream close.

Edgar




More information about the Squeak-dev mailing list