[squeak-dev] Rio: exceptions documentation

Keith Hodges keith_hodges at yahoo.co.uk
Fri Nov 28 16:49:37 UTC 2008


Casimiro de Almeida Barreto wrote:
> Hello,
>
> I had a code like:
>
> [ aStream := CrLfFileStream new open: 'aGivenFileName' forWrite: false ]
>     on: FileDoesNotExistException do: [ :exception |  <code ....> ].
>
> It worked ok. But with:
>
> [ aStream := 'aGivenFileName' asRio reader ] on:
> FileDoesNotExistException do: [ :exception | <code ...> ].
>
> things just don't work... Where I can find exceptions documentation (in
> particular for Rio) ?
>
> Besides, it seems that the atEnd message is delayed by one entry (in the
> first case 1025 lines are correctly read and in the second case it goes
> one line ahead in the file).
>     
Hello Casmiro,

great to see you using Rio. The latest version has moved away from using
"Rio" in the code and is now (for better or worse) using classes called
File/Directory.

Rio doesnt use exceptions very much at all for various reasons. It is
relatively easy to test for existence, and there are other utilities
provided.

In your case where you want a basic stream,

"returns nil if the file does not exist"
aStream := 'aGivenFileName' asFile reader.

"returns nil if the file does not exist"
data  = 'aGivenFileName' asFile contents.

"The reading block is ignored if the file does not exist"
'aGivenFileName' asFile reader: [ :str |  aChar := str next ].

"an explicit checks for existence are available via"
'aGivenFileName' asFile ifFileDo: [ :f | f contents ].
'aGivenFileName' asFile ifExistsDo: [ :f | f contents ].
'aGivenFileName' asFile ifAbsentDo: [ :f | f touch ].

The latest Rio is available from Universes, be prepared to replace
senders of asRio with asFile/asDirectory

thanks for the feedback, knowing the above wold you rather have
exceptions still?

best regards

Keith






More information about the Squeak-dev mailing list