QuerySignal.st
changeset 1379 bde210aaccc2
parent 1363 461c6d002b63
child 1422 9a0b792f2953
--- a/QuerySignal.st	Sun May 12 15:23:22 1996 +0200
+++ b/QuerySignal.st	Sun May 12 15:23:46 1996 +0200
@@ -71,34 +71,122 @@
 
 examples 
 "
-    an up-query from a deeply nested operation to a higher level:
+  an up-query from a deeply nested operation to a higher level:
                                                                         [exBegin]
-        |querySignal zero|
+    |querySignal zero|
 
-        zero := 0.
-        querySignal := QuerySignal new.
-        querySignal handle:[:ex |
-            ex proceedWith:true
-        ] do:[
-            'nexting'.
+    zero := 0.
+    querySignal := QuerySignal new.
+    querySignal handle:[:ex |
+        Transcript showCr:'query'.
+        ex proceedWith:true
+    ] do:[
+        'nesting'.
+        [
+            [
+                Object errorSignal handle:[:ex |
+                    Transcript showCr:'some error: ' , ex errorString.
+                    ex proceed
+                ] do:[
+                    [
+                        1 // zero.  'an error which is cought in the handler'.
+                        (querySignal raise) == true ifTrue:[
+                            Transcript showCr:'query says: ok'.
+                        ] ifFalse:[
+                            Transcript showCr:'query says: no'
+                        ]
+                    ] value
+                ]
+            ] value
+        ] value
+    ]
+                                                                        [exEnd]
+  an up-query from a deeply nested operation, for which there
+  is no handler:
+  (notice, this would not work with normal signals, which would raise
+   another unhandled exception-exception;
+   also notice the == check #raise's return value being true,
+   instead of a simple ifTrue; this handles a nil-value from
+   the unhandled query)
+                                                                        [exBegin]
+    |querySignal zero|
+
+    zero := 0.
+    querySignal := QuerySignal new.
+
+    [
+        'nesting'.
+        [
+            [
+                Object errorSignal handle:[:ex |
+                    Transcript showCr:'some error: ' , ex errorString.
+                    ex proceed
+                ] do:[
+                    [
+                        1 // zero.  'an error which is cought in the handler'.
+                        (querySignal raise) == true ifTrue:[
+                            Transcript showCr:'query says: ok'.
+                        ] ifFalse:[
+                            Transcript showCr:'query says: no'
+                        ]
+                    ] value
+                ]
+            ] value
+        ] value
+    ] value
+                                                                         [exEnd]
+  counter-example, just to show that things would not work this way
+  with regular signals:
+                                                                        [exBegin]
+    |signal|
+
+    signal := Signal new.
+    'nesting deeply'.
+    [
+        [
             [
                 [
-                    Object errorSignal handle:[:ex |
-                        ex proceed
-                    ] do:[
-                        [
-                            1 // zero.  'a cought error'.
-                            (querySignal raise) ifTrue:[
-                                Transcript showCr:'query says: ok'.
-                             ] ifFalse:[
-                                Transcript showCr:'query says: no'
-                             ]
-                        ] value
-                    ]
+                    [
+                        (signal raise) == true ifTrue:[
+                            Transcript showCr:'query says: ok'.
+                        ] ifFalse:[
+                            Transcript showCr:'query says: no'
+                        ]
+                    ] value
                 ] value
             ] value
-        ]
-                                                                        [exEnd]
+        ] value
+    ] value
+                                                                         [exEnd]
+
+   except, by handling the unhandled exception
+   (but we think, that querySignals are easier to use and
+    better document the intent):
+                                                                        [exBegin]
+    |signal|
+
+    signal := Signal new.
+    'nesting deeply'.
+    [
+        [
+            [
+                [
+                    [
+                        Signal noHandlerSignal handle:[:ex |
+                            ex proceedWith:nil
+                        ] do:[
+                            (signal raise) == true ifTrue:[
+                                Transcript showCr:'query says: ok'.
+                            ] ifFalse:[
+                                Transcript showCr:'query says: no'
+                            ]
+                        ]
+                    ] value
+                ] value
+            ] value
+        ] value
+    ] value
+                                                                         [exEnd]
 "
 ! !
 
@@ -131,5 +219,5 @@
 !QuerySignal class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/QuerySignal.st,v 1.11 1996-05-09 13:23:57 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/QuerySignal.st,v 1.12 1996-05-12 13:23:46 cg Exp $'
 ! !