better errorHandling in readFrom:onError:
authorClaus Gittinger <cg@exept.de>
Tue, 08 Oct 1996 20:34:08 +0200
changeset 1701 80d13adb2e77
parent 1700 25223802076c
child 1702 777b74f65c7e
better errorHandling in readFrom:onError:
AbsTime.st
AbsoluteTime.st
Date.st
Number.st
Point.st
Time.st
Timestamp.st
--- a/AbsTime.st	Tue Oct 08 20:32:31 1996 +0200
+++ b/AbsTime.st	Tue Oct 08 20:34:08 1996 +0200
@@ -150,53 +150,57 @@
      Notice, that this is not the storeString format and 
      is different from the format expected by readFrom:."
 
-    |str day month year hour min sec millis ex|
-
-    str := aStringOrStream readStream.
+    ErrorSignal handle:[:ex |
+        ^ exceptionBlock value
+    ] do:[
+        |str day month year hour min sec millis ex|
 
-    ex := [^ exceptionBlock value].
-    day := Integer readFrom:str onError:ex.
-    (day between:1 and:31) ifFalse:[^ exceptionBlock value].
+        str := aStringOrStream readStream.
+
+        ex := [^ exceptionBlock value].
+        day := Integer readFrom:str onError:ex.
+        (day between:1 and:31) ifFalse:[^ exceptionBlock value].
 
-    [str peek isDigit] whileFalse:[str next].
-    month := Integer readFrom:str onError:ex.
-    (month between:1 and:12) ifFalse:[^ exceptionBlock value].
+        [str peek isDigit] whileFalse:[str next].
+        month := Integer readFrom:str onError:ex.
+        (month between:1 and:12) ifFalse:[^ exceptionBlock value].
 
-    [str peek isDigit] whileFalse:[str next].
-    year := Integer readFrom:str onError:ex.
+        [str peek isDigit] whileFalse:[str next].
+        year := Integer readFrom:str onError:ex.
 
-    [str peek isDigit] whileFalse:[str next].
-    hour := Integer readFrom:str onError:ex.
-    (hour between:0 and:24) ifFalse:[^ exceptionBlock value].
+        [str peek isDigit] whileFalse:[str next].
+        hour := Integer readFrom:str onError:ex.
+        (hour between:0 and:24) ifFalse:[^ exceptionBlock value].
 
-    [str peek isDigit] whileFalse:[str next].
-    min := Integer readFrom:str onError:ex.
-    (min between:0 and:59) ifFalse:[^ exceptionBlock value].
+        [str peek isDigit] whileFalse:[str next].
+        min := Integer readFrom:str onError:ex.
+        (min between:0 and:59) ifFalse:[^ exceptionBlock value].
 
-    [str peek isDigit] whileFalse:[str next].
-    sec := Integer readFrom:str onError:ex.
-    (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
+        [str peek isDigit] whileFalse:[str next].
+        sec := Integer readFrom:str onError:ex.
+        (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
 
-    str peek = '.' ifTrue:[
-        str next.
-        millis := Integer readFrom:str onError:ex.
-    ] ifFalse:[
-        millis := 0.
-    ].
+        str peek = '.' ifTrue:[
+            str next.
+            millis := Integer readFrom:str onError:ex.
+        ] ifFalse:[
+            millis := 0.
+        ].
 
-    "special check"
-    hour == 24 ifTrue:[
-        (min ~~ 0 or:[sec ~~ 0]) ifTrue:[^ exceptionBlock value].
+        "special check"
+        hour == 24 ifTrue:[
+            (min ~~ 0 or:[sec ~~ 0]) ifTrue:[^ exceptionBlock value].
+        ].
+
+        ^ self day:day month:month year:year hour:hour minutes:min seconds:sec
     ].
 
-    ^ self day:day month:month year:year hour:hour minutes:min seconds:sec
-
     "
      AbsoluteTime readFrom:'20-2-1995 13:11:06'    
      AbsoluteTime readFrom:'20-2-1995 13:11:06.100'    
     "
 
-    "Modified: 1.7.1996 / 14:44:09 / cg"
+    "Modified: 8.10.1996 / 19:25:59 / cg"
 ! !
 
 !AbsoluteTime methodsFor:'accessing'!
@@ -648,5 +652,5 @@
 !AbsoluteTime  class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Attic/AbsTime.st,v 1.29 1996-09-20 07:27:00 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Attic/AbsTime.st,v 1.30 1996-10-08 18:33:36 cg Exp $'
 ! !
--- a/AbsoluteTime.st	Tue Oct 08 20:32:31 1996 +0200
+++ b/AbsoluteTime.st	Tue Oct 08 20:34:08 1996 +0200
@@ -150,53 +150,57 @@
      Notice, that this is not the storeString format and 
      is different from the format expected by readFrom:."
 
-    |str day month year hour min sec millis ex|
-
-    str := aStringOrStream readStream.
+    ErrorSignal handle:[:ex |
+        ^ exceptionBlock value
+    ] do:[
+        |str day month year hour min sec millis ex|
 
-    ex := [^ exceptionBlock value].
-    day := Integer readFrom:str onError:ex.
-    (day between:1 and:31) ifFalse:[^ exceptionBlock value].
+        str := aStringOrStream readStream.
+
+        ex := [^ exceptionBlock value].
+        day := Integer readFrom:str onError:ex.
+        (day between:1 and:31) ifFalse:[^ exceptionBlock value].
 
-    [str peek isDigit] whileFalse:[str next].
-    month := Integer readFrom:str onError:ex.
-    (month between:1 and:12) ifFalse:[^ exceptionBlock value].
+        [str peek isDigit] whileFalse:[str next].
+        month := Integer readFrom:str onError:ex.
+        (month between:1 and:12) ifFalse:[^ exceptionBlock value].
 
-    [str peek isDigit] whileFalse:[str next].
-    year := Integer readFrom:str onError:ex.
+        [str peek isDigit] whileFalse:[str next].
+        year := Integer readFrom:str onError:ex.
 
-    [str peek isDigit] whileFalse:[str next].
-    hour := Integer readFrom:str onError:ex.
-    (hour between:0 and:24) ifFalse:[^ exceptionBlock value].
+        [str peek isDigit] whileFalse:[str next].
+        hour := Integer readFrom:str onError:ex.
+        (hour between:0 and:24) ifFalse:[^ exceptionBlock value].
 
-    [str peek isDigit] whileFalse:[str next].
-    min := Integer readFrom:str onError:ex.
-    (min between:0 and:59) ifFalse:[^ exceptionBlock value].
+        [str peek isDigit] whileFalse:[str next].
+        min := Integer readFrom:str onError:ex.
+        (min between:0 and:59) ifFalse:[^ exceptionBlock value].
 
-    [str peek isDigit] whileFalse:[str next].
-    sec := Integer readFrom:str onError:ex.
-    (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
+        [str peek isDigit] whileFalse:[str next].
+        sec := Integer readFrom:str onError:ex.
+        (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
 
-    str peek = '.' ifTrue:[
-        str next.
-        millis := Integer readFrom:str onError:ex.
-    ] ifFalse:[
-        millis := 0.
-    ].
+        str peek = '.' ifTrue:[
+            str next.
+            millis := Integer readFrom:str onError:ex.
+        ] ifFalse:[
+            millis := 0.
+        ].
 
-    "special check"
-    hour == 24 ifTrue:[
-        (min ~~ 0 or:[sec ~~ 0]) ifTrue:[^ exceptionBlock value].
+        "special check"
+        hour == 24 ifTrue:[
+            (min ~~ 0 or:[sec ~~ 0]) ifTrue:[^ exceptionBlock value].
+        ].
+
+        ^ self day:day month:month year:year hour:hour minutes:min seconds:sec
     ].
 
-    ^ self day:day month:month year:year hour:hour minutes:min seconds:sec
-
     "
      AbsoluteTime readFrom:'20-2-1995 13:11:06'    
      AbsoluteTime readFrom:'20-2-1995 13:11:06.100'    
     "
 
-    "Modified: 1.7.1996 / 14:44:09 / cg"
+    "Modified: 8.10.1996 / 19:25:59 / cg"
 ! !
 
 !AbsoluteTime methodsFor:'accessing'!
@@ -648,5 +652,5 @@
 !AbsoluteTime  class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Attic/AbsoluteTime.st,v 1.29 1996-09-20 07:27:00 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Attic/AbsoluteTime.st,v 1.30 1996-10-08 18:33:36 cg Exp $'
 ! !
--- a/Date.st	Tue Oct 08 20:32:31 1996 +0200
+++ b/Date.st	Tue Oct 08 20:34:08 1996 +0200
@@ -201,11 +201,11 @@
        of the german/french and other day-month-year.
        There ought to be a nationalized variant of this."
 
-    |str month day year|
-
     ErrorSignal handle:[:ex |
         ^ exceptionBlock value
     ] do:[
+        |str month day year|
+
         str := aStringOrStream readStream.
 
         [str peek isLetterOrDigit] whileFalse:[str next].
@@ -240,7 +240,7 @@
     "
 
     "Created: 16.11.1995 / 22:50:17 / cg"
-    "Modified: 20.2.1996 / 20:12:07 / cg"
+    "Modified: 8.10.1996 / 19:25:39 / cg"
 !
 
 today
@@ -1250,6 +1250,6 @@
 !Date  class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.36 1996-07-01 13:33:00 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.37 1996-10-08 18:33:03 cg Exp $'
 ! !
 Date initialize!
--- a/Number.st	Tue Oct 08 20:32:31 1996 +0200
+++ b/Number.st	Tue Oct 08 20:34:08 1996 +0200
@@ -53,13 +53,13 @@
      skipping all whitespace first; return the value of exceptionBlock,
      if no number can be read."
 
-    |str nextChar radix value negative signExp freakOut|
-
-    str := aStringOrStream readStream.
-
     ErrorSignal handle:[:ex |
         ^ exceptionBlock value
     ] do:[
+        |str nextChar radix value negative signExp freakOut|
+
+        str := aStringOrStream readStream.
+
         nextChar := str skipSeparators.
         nextChar isNil ifTrue:[^ exceptionBlock value].
 
@@ -129,7 +129,7 @@
      '+00000123.45' asNumber  
     "
 
-    "Modified: 20.2.1996 / 20:24:19 / cg"
+    "Modified: 8.10.1996 / 19:24:01 / cg"
 !
 
 readSmalltalkSyntaxFrom:aStream
@@ -463,5 +463,5 @@
 !Number  class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Number.st,v 1.35 1996-08-19 07:58:23 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Number.st,v 1.36 1996-10-08 18:33:47 cg Exp $'
 ! !
--- a/Point.st	Tue Oct 08 20:32:31 1996 +0200
+++ b/Point.st	Tue Oct 08 20:34:08 1996 +0200
@@ -17,7 +17,7 @@
 	category:'Graphics-Geometry'
 !
 
-!Point class methodsFor:'documentation'!
+!Point  class methodsFor:'documentation'!
 
 copyright
 "
@@ -56,7 +56,7 @@
 "
 ! !
 
-!Point class methodsFor:'initialization'!
+!Point  class methodsFor:'initialization'!
 
 initialize
     PointZero isNil ifTrue:[
@@ -65,7 +65,7 @@
     ]
 ! !
 
-!Point class methodsFor:'instance creation'!
+!Point  class methodsFor:'instance creation'!
 
 r:distance angle:angle
     "create and return a new point given polar coordinates.
@@ -93,19 +93,23 @@
      skipping all whitespace first; return the value of exceptionBlock,
      if no point can be read."
 
-    |str newX newY|
+    ErrorSignal handle:[:ex |
+        ^ exceptionBlock value
+    ] do:[
+        |str newX newY|
 
-    str := aStringOrStream readStream.
+        str := aStringOrStream readStream.
 
-    newX := Number readFrom:str onError:nil.
-    newX notNil ifTrue:[
-	(str skipSeparators == $@) ifTrue:[
-	    str  next.
-	    newY := Number readFrom:str onError:nil.
-	    newY notNil ifTrue:[
-		^ self x:newX y:newY
-	    ]
-	]
+        newX := Number readFrom:str onError:nil.
+        newX notNil ifTrue:[
+            (str skipSeparators == $@) ifTrue:[
+                str  next.
+                newY := Number readFrom:str onError:nil.
+                newY notNil ifTrue:[
+                    ^ self x:newX y:newY
+                ]
+            ]
+        ].
     ].
     ^ exceptionBlock value
 
@@ -116,7 +120,7 @@
      Point readFrom:('fooBar' readStream) onError:[0@0]
     "
 
-    "Modified: 16.11.1995 / 22:50:45 / cg"
+    "Modified: 8.10.1996 / 19:31:39 / cg"
 !
 
 x:newX y:newY
@@ -148,7 +152,7 @@
     ^ (self basicNew) x:newX y:newY
 ! !
 
-!Point class methodsFor:'constants'!
+!Point  class methodsFor:'constants'!
 
 unity
     "return the neutral element for multiplication"
@@ -162,7 +166,7 @@
     ^ PointZero
 ! !
 
-!Point class methodsFor:'queries'!
+!Point  class methodsFor:'queries'!
 
 isBuiltInClass
     "return true if this class is known by the run-time-system.
@@ -899,9 +903,9 @@
     ^ self + anOffset
 ! !
 
-!Point class methodsFor:'documentation'!
+!Point  class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Point.st,v 1.38 1996-05-08 18:16:47 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Point.st,v 1.39 1996-10-08 18:34:08 cg Exp $'
 ! !
 Point initialize!
--- a/Time.st	Tue Oct 08 20:32:31 1996 +0200
+++ b/Time.st	Tue Oct 08 20:34:08 1996 +0200
@@ -88,28 +88,32 @@
      If no pm follows the time, the string is interpreted as either 24 hour format
      or being am."
 
-    |str hour min sec ex|
-
-    str := aStringOrStream readStream.
+    ErrorSignal handle:[:ex |
+        ^ exceptionBlock value
+    ] do:[
+        |str hour min sec ex|
 
-    ex := [^ exceptionBlock value].
-    hour := Integer readFrom:str onError:ex.
-    (hour between:0 and:24) ifFalse:[ex value].
+        str := aStringOrStream readStream.
+
+        ex := [^ exceptionBlock value].
+        hour := Integer readFrom:str onError:ex.
+        (hour between:0 and:24) ifFalse:[ex value].
 
-    [str peek isDigit] whileFalse:[str next].
-    min := Integer readFrom:str onError:ex.
-    (min between:0 and:59) ifFalse:[ex value].
+        [str peek isDigit] whileFalse:[str next].
+        min := Integer readFrom:str onError:ex.
+        (min between:0 and:59) ifFalse:[ex value].
+
+        [str peek isDigit] whileFalse:[str next].
+        sec := Integer readFrom:str onError:ex.
+        (sec between:0 and:59) ifFalse:[ex value].
 
-    [str peek isDigit] whileFalse:[str next].
-    sec := Integer readFrom:str onError:ex.
-    (sec between:0 and:59) ifFalse:[ex value].
-
-    [str peek == Character space] whileTrue:[str next].
-    (str peek == $p) ifTrue:[
-	"pm"
-	hour := hour + 12
-    ].
-    ^ self basicNew setHour:hour minutes:min seconds:sec
+        [str peek == Character space] whileTrue:[str next].
+        (str peek == $p) ifTrue:[
+            "pm"
+            hour := hour + 12
+        ].
+        ^ self basicNew setHour:hour minutes:min seconds:sec
+    ]
 
     "
      Time readFrom:'18:22:00'    
@@ -120,7 +124,7 @@
      Time readFrom:'7:00:11 am'  
     "
 
-    "Modified: 16.11.1995 / 22:51:20 / cg"
+    "Modified: 8.10.1996 / 19:32:11 / cg"
 ! !
 
 !Time methodsFor:'accessing'!
@@ -366,5 +370,5 @@
 !Time  class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.29 1996-07-01 13:35:03 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.30 1996-10-08 18:33:57 cg Exp $'
 ! !
--- a/Timestamp.st	Tue Oct 08 20:32:31 1996 +0200
+++ b/Timestamp.st	Tue Oct 08 20:34:08 1996 +0200
@@ -150,53 +150,57 @@
      Notice, that this is not the storeString format and 
      is different from the format expected by readFrom:."
 
-    |str day month year hour min sec millis ex|
-
-    str := aStringOrStream readStream.
+    ErrorSignal handle:[:ex |
+        ^ exceptionBlock value
+    ] do:[
+        |str day month year hour min sec millis ex|
 
-    ex := [^ exceptionBlock value].
-    day := Integer readFrom:str onError:ex.
-    (day between:1 and:31) ifFalse:[^ exceptionBlock value].
+        str := aStringOrStream readStream.
+
+        ex := [^ exceptionBlock value].
+        day := Integer readFrom:str onError:ex.
+        (day between:1 and:31) ifFalse:[^ exceptionBlock value].
 
-    [str peek isDigit] whileFalse:[str next].
-    month := Integer readFrom:str onError:ex.
-    (month between:1 and:12) ifFalse:[^ exceptionBlock value].
+        [str peek isDigit] whileFalse:[str next].
+        month := Integer readFrom:str onError:ex.
+        (month between:1 and:12) ifFalse:[^ exceptionBlock value].
 
-    [str peek isDigit] whileFalse:[str next].
-    year := Integer readFrom:str onError:ex.
+        [str peek isDigit] whileFalse:[str next].
+        year := Integer readFrom:str onError:ex.
 
-    [str peek isDigit] whileFalse:[str next].
-    hour := Integer readFrom:str onError:ex.
-    (hour between:0 and:24) ifFalse:[^ exceptionBlock value].
+        [str peek isDigit] whileFalse:[str next].
+        hour := Integer readFrom:str onError:ex.
+        (hour between:0 and:24) ifFalse:[^ exceptionBlock value].
 
-    [str peek isDigit] whileFalse:[str next].
-    min := Integer readFrom:str onError:ex.
-    (min between:0 and:59) ifFalse:[^ exceptionBlock value].
+        [str peek isDigit] whileFalse:[str next].
+        min := Integer readFrom:str onError:ex.
+        (min between:0 and:59) ifFalse:[^ exceptionBlock value].
 
-    [str peek isDigit] whileFalse:[str next].
-    sec := Integer readFrom:str onError:ex.
-    (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
+        [str peek isDigit] whileFalse:[str next].
+        sec := Integer readFrom:str onError:ex.
+        (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
 
-    str peek = '.' ifTrue:[
-        str next.
-        millis := Integer readFrom:str onError:ex.
-    ] ifFalse:[
-        millis := 0.
-    ].
+        str peek = '.' ifTrue:[
+            str next.
+            millis := Integer readFrom:str onError:ex.
+        ] ifFalse:[
+            millis := 0.
+        ].
 
-    "special check"
-    hour == 24 ifTrue:[
-        (min ~~ 0 or:[sec ~~ 0]) ifTrue:[^ exceptionBlock value].
+        "special check"
+        hour == 24 ifTrue:[
+            (min ~~ 0 or:[sec ~~ 0]) ifTrue:[^ exceptionBlock value].
+        ].
+
+        ^ self day:day month:month year:year hour:hour minutes:min seconds:sec
     ].
 
-    ^ self day:day month:month year:year hour:hour minutes:min seconds:sec
-
     "
      AbsoluteTime readFrom:'20-2-1995 13:11:06'    
      AbsoluteTime readFrom:'20-2-1995 13:11:06.100'    
     "
 
-    "Modified: 1.7.1996 / 14:44:09 / cg"
+    "Modified: 8.10.1996 / 19:25:59 / cg"
 ! !
 
 !AbsoluteTime methodsFor:'accessing'!
@@ -648,5 +652,5 @@
 !AbsoluteTime  class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.29 1996-09-20 07:27:00 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.30 1996-10-08 18:33:36 cg Exp $'
 ! !