(Integer readFrom: 'abc' readStream) = 0

Zulq Alam me at zulq.net
Tue Jan 8 14:57:46 UTC 2008

I was surprised to find that Integer class>>#readFrom: returns 0 when it 
doesn't find an integer. So, (Integer readFrom: 'abc' readStream) = 0 is 
true. This seems wrong to me although it's consistent with the method 
comment and VisualWorks. I was expecting an error. What's the reasoning 
behind this?

I'm looking for the Smalltalk equivalent of:

try {
catch (NumberFormatException e) {
   // do something

I found SqNumberParser which appears to be what I want:

(SqNumberParser on: 'abc')
	nextIntegerBase: 10
	ifFail: [self doSomething]

This works but, is it the right / good way?

Does the Sq prefix mean this parser is expecting Squeak format numbers? 
If so, what is this format?

Also, how is this done in other smalltalks?


More information about the Squeak-dev mailing list