420
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
Signal subclass:#QuerySignal
|
1248
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Kernel-Exceptions'
|
420
|
18 |
!
|
|
19 |
|
|
20 |
!QuerySignal class methodsFor:'documentation'!
|
|
21 |
|
|
22 |
copyright
|
|
23 |
"
|
|
24 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
25 |
All Rights Reserved
|
|
26 |
|
|
27 |
This software is furnished under a license and may be used
|
|
28 |
only in accordance with the terms of that license and with the
|
|
29 |
inclusion of the above copyright notice. This software may not
|
|
30 |
be provided or otherwise made available to, or used by, any
|
|
31 |
other person. No title to or ownership of the software is
|
|
32 |
hereby transferred.
|
|
33 |
"
|
|
34 |
!
|
|
35 |
|
|
36 |
documentation
|
|
37 |
"
|
|
38 |
QuerySignals are like signals, except that they are not accepted
|
|
39 |
by handlers for ordinary signals.
|
|
40 |
I.e. a signal handler for a normal signal will not handle a query
|
580
|
41 |
signal. Thus, these bypass anySignal handlers.
|
1248
|
42 |
If unhandled, no error is raised, instead they are simply ignored
|
|
43 |
(as opposed to normal signals, which raise an unhandled signal exception).
|
1363
|
44 |
QuerySignals are also ignored, if a handler exists, but rejects.
|
1248
|
45 |
|
1363
|
46 |
Their main use is to implement up-Queries via signals, that work even
|
|
47 |
if intermediate errorSignal handlers are present
|
|
48 |
(which is not possible with ordinary signals, since errorSignal handlers
|
|
49 |
would catch those signals).
|
|
50 |
|
1248
|
51 |
Code deep down in the calling hierarchy can post such an up-Query to ask
|
|
52 |
for some information in return or to pass some information upward.
|
580
|
53 |
|
1248
|
54 |
For example, the activityNotification mechanism is built on top of this:
|
|
55 |
everyone can send such a notification which is either handled by someone
|
|
56 |
up in the hierarchy (to show it in the windows info area) or simply
|
|
57 |
ignored.
|
|
58 |
|
|
59 |
Using QuerySignals for this (instead of regular Signals) helps in documenting
|
|
60 |
the intended usage of those signals.
|
1275
|
61 |
|
|
62 |
[see also:]
|
|
63 |
Signal SignalSet Exception
|
|
64 |
Object
|
1363
|
65 |
(``Exception handling and signals'': programming/exceptions.html)
|
1292
|
66 |
|
|
67 |
[author:]
|
|
68 |
Claus Gittinger
|
580
|
69 |
"
|
|
70 |
!
|
|
71 |
|
|
72 |
examples
|
|
73 |
"
|
1379
|
74 |
an up-query from a deeply nested operation to a higher level:
|
1316
|
75 |
[exBegin]
|
1379
|
76 |
|querySignal zero|
|
580
|
77 |
|
1379
|
78 |
zero := 0.
|
|
79 |
querySignal := QuerySignal new.
|
|
80 |
querySignal handle:[:ex |
|
1422
|
81 |
Transcript showCR:'query'.
|
1379
|
82 |
ex proceedWith:true
|
|
83 |
] do:[
|
|
84 |
'nesting'.
|
|
85 |
[
|
|
86 |
[
|
|
87 |
Object errorSignal handle:[:ex |
|
1422
|
88 |
Transcript showCR:'some error: ' , ex errorString.
|
1379
|
89 |
ex proceed
|
|
90 |
] do:[
|
|
91 |
[
|
|
92 |
1 // zero. 'an error which is cought in the handler'.
|
|
93 |
(querySignal raise) == true ifTrue:[
|
1422
|
94 |
Transcript showCR:'query says: ok'.
|
1379
|
95 |
] ifFalse:[
|
1422
|
96 |
Transcript showCR:'query says: no'
|
1379
|
97 |
]
|
|
98 |
] value
|
|
99 |
]
|
|
100 |
] value
|
|
101 |
] value
|
|
102 |
]
|
|
103 |
[exEnd]
|
|
104 |
an up-query from a deeply nested operation, for which there
|
|
105 |
is no handler:
|
|
106 |
(notice, this would not work with normal signals, which would raise
|
|
107 |
another unhandled exception-exception;
|
|
108 |
also notice the == check #raise's return value being true,
|
|
109 |
instead of a simple ifTrue; this handles a nil-value from
|
|
110 |
the unhandled query)
|
|
111 |
[exBegin]
|
|
112 |
|querySignal zero|
|
|
113 |
|
|
114 |
zero := 0.
|
|
115 |
querySignal := QuerySignal new.
|
|
116 |
|
|
117 |
[
|
|
118 |
'nesting'.
|
|
119 |
[
|
|
120 |
[
|
|
121 |
Object errorSignal handle:[:ex |
|
1422
|
122 |
Transcript showCR:'some error: ' , ex errorString.
|
1379
|
123 |
ex proceed
|
|
124 |
] do:[
|
|
125 |
[
|
|
126 |
1 // zero. 'an error which is cought in the handler'.
|
|
127 |
(querySignal raise) == true ifTrue:[
|
1422
|
128 |
Transcript showCR:'query says: ok'.
|
1379
|
129 |
] ifFalse:[
|
1422
|
130 |
Transcript showCR:'query says: no'
|
1379
|
131 |
]
|
|
132 |
] value
|
|
133 |
]
|
|
134 |
] value
|
|
135 |
] value
|
|
136 |
] value
|
|
137 |
[exEnd]
|
|
138 |
counter-example, just to show that things would not work this way
|
|
139 |
with regular signals:
|
|
140 |
[exBegin]
|
|
141 |
|signal|
|
|
142 |
|
|
143 |
signal := Signal new.
|
|
144 |
'nesting deeply'.
|
|
145 |
[
|
|
146 |
[
|
1316
|
147 |
[
|
|
148 |
[
|
1379
|
149 |
[
|
|
150 |
(signal raise) == true ifTrue:[
|
1422
|
151 |
Transcript showCR:'query says: ok'.
|
1379
|
152 |
] ifFalse:[
|
1422
|
153 |
Transcript showCR:'query says: no'
|
1379
|
154 |
]
|
|
155 |
] value
|
1316
|
156 |
] value
|
|
157 |
] value
|
1379
|
158 |
] value
|
|
159 |
] value
|
|
160 |
[exEnd]
|
|
161 |
|
|
162 |
except, by handling the unhandled exception
|
|
163 |
(but we think, that querySignals are easier to use and
|
|
164 |
better document the intent):
|
|
165 |
[exBegin]
|
|
166 |
|signal|
|
|
167 |
|
|
168 |
signal := Signal new.
|
|
169 |
'nesting deeply'.
|
|
170 |
[
|
|
171 |
[
|
|
172 |
[
|
|
173 |
[
|
|
174 |
[
|
|
175 |
Signal noHandlerSignal handle:[:ex |
|
|
176 |
ex proceedWith:nil
|
|
177 |
] do:[
|
|
178 |
(signal raise) == true ifTrue:[
|
1422
|
179 |
Transcript showCR:'query says: ok'.
|
1379
|
180 |
] ifFalse:[
|
1422
|
181 |
Transcript showCR:'query says: no'
|
1379
|
182 |
]
|
|
183 |
]
|
|
184 |
] value
|
|
185 |
] value
|
|
186 |
] value
|
|
187 |
] value
|
|
188 |
] value
|
|
189 |
[exEnd]
|
420
|
190 |
"
|
|
191 |
! !
|
|
192 |
|
|
193 |
!QuerySignal methodsFor:'queries'!
|
|
194 |
|
|
195 |
accepts:aSignal
|
|
196 |
"return true, if the receiver accepts the argument, aSignal.
|
|
197 |
(i.e. the receiver is aSignal or a parent of it). False otherwise."
|
|
198 |
|
|
199 |
|s|
|
|
200 |
|
421
|
201 |
aSignal isQuerySignal ifFalse:[^ false].
|
420
|
202 |
|
|
203 |
s := aSignal.
|
|
204 |
[s notNil] whileTrue:[
|
|
205 |
self == s ifTrue:[^ true].
|
|
206 |
s := s parent
|
|
207 |
].
|
|
208 |
^ false
|
691
|
209 |
!
|
|
210 |
|
|
211 |
isQuerySignal
|
1249
|
212 |
"return true, if this is a querySignal - always return true here"
|
|
213 |
|
691
|
214 |
^ true
|
1249
|
215 |
|
|
216 |
"Modified: 22.4.1996 / 13:45:10 / cg"
|
420
|
217 |
! !
|
691
|
218 |
|
|
219 |
!QuerySignal class methodsFor:'documentation'!
|
|
220 |
|
|
221 |
version
|
1422
|
222 |
^ '$Header: /cvs/stx/stx/libbasic/QuerySignal.st,v 1.13 1996-05-18 15:29:41 cg Exp $'
|
691
|
223 |
! !
|