author | Stefan Vogel <sv@exept.de> |
Wed, 28 Jul 1999 09:53:29 +0200 | |
changeset 4464 | cec93c942c14 |
parent 4446 | 4da4e51fc1ab |
child 4466 | 9cba6f4ecec4 |
permissions | -rw-r--r-- |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
1 |
'From Smalltalk/X, Version:3.5.3 on 26-jul-1999 at 00:02:41' ! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
2 |
|
4446 | 3 |
Exception subclass:#Query |
4 |
instanceVariableNames:'' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'Kernel-Exceptions' |
|
8 |
! |
|
9 |
||
10 |
!Query class methodsFor:'documentation'! |
|
11 |
||
12 |
documentation |
|
13 |
" |
|
14 |
Query ist an abstract superclass of all query exceptions in the system |
|
15 |
||
16 |
[author:] |
|
17 |
Stefan Vogel |
|
18 |
||
19 |
[see also:] |
|
20 |
Signal QuerySignal |
|
21 |
" |
|
22 |
||
23 |
! |
|
24 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
25 |
examples |
4446 | 26 |
" |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
27 |
an up-query from a deeply nested operation to a higher level: |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
28 |
[exBegin] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
29 |
|zero| |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
30 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
31 |
zero := 0. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
32 |
Query handle:[:ex | |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
33 |
Transcript showCR:'query'. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
34 |
ex proceedWith:true |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
35 |
] do:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
36 |
'nesting'. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
37 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
38 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
39 |
Object errorSignal handle:[:ex | |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
40 |
Transcript showCR:'some error: ' , ex errorString. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
41 |
ex proceed |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
42 |
] do:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
43 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
44 |
1 // zero. 'an error which is caught in the handler'. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
45 |
(Query query) == true ifTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
46 |
Transcript showCR:'query says: ok'. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
47 |
] ifFalse:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
48 |
Transcript showCR:'query says: no' |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
49 |
] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
50 |
] value |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
51 |
] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
52 |
] value |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
53 |
] value |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
54 |
] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
55 |
[exEnd] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
56 |
for lazy typists, a more compact interface is also provided |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
57 |
(which is also easier to read): |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
58 |
[exBegin] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
59 |
Query answer:true do:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
60 |
'nesting'. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
61 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
62 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
63 |
(Query query) == true ifTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
64 |
Transcript showCR:'query says: ok'. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
65 |
] ifFalse:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
66 |
Transcript showCR:'query says: no' |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
67 |
] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
68 |
] value |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
69 |
] value |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
70 |
] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
71 |
[exEnd] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
72 |
an up-query from a deeply nested operation, for which there |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
73 |
is no handler: |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
74 |
(notice, this would not work with normal signals, which would raise |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
75 |
another unhandled exception-exception; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
76 |
also notice the == check #raise's return value being true, |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
77 |
instead of a simple ifTrue; this handles a nil-value from |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
78 |
the unhandled query) |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
79 |
[exBegin] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
80 |
|zero| |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
81 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
82 |
zero := 0. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
83 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
84 |
'nesting'. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
85 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
86 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
87 |
Object errorSignal handle:[:ex | |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
88 |
Transcript showCR:'some error: ' , ex errorString. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
89 |
ex proceed |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
90 |
] do:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
91 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
92 |
1 // zero. 'an error which is caught in the handler'. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
93 |
(Query raise) == true ifTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
94 |
Transcript showCR:'query says: ok'. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
95 |
] ifFalse:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
96 |
Transcript showCR:'query says: no' |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
97 |
] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
98 |
] value |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
99 |
] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
100 |
] value |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
101 |
] value |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
102 |
] value |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
103 |
[exEnd] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
104 |
counter-example, just to show that things would not work this way |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
105 |
with regular signals: |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
106 |
[exBegin] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
107 |
|signal| |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
108 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
109 |
signal := Signal new. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
110 |
'nesting deeply'. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
111 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
112 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
113 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
114 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
115 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
116 |
(signal raise) == true ifTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
117 |
Transcript showCR:'query says: ok'. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
118 |
] ifFalse:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
119 |
Transcript showCR:'query says: no' |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
120 |
] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
121 |
] value |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
122 |
] value |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
123 |
] value |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
124 |
] value |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
125 |
] value |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
126 |
[exEnd] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
127 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
128 |
except, by handling the unhandled exception |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
129 |
(but we think, that querySignals are easier to use and |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
130 |
better document the intent): |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
131 |
[exBegin] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
132 |
|signal| |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
133 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
134 |
signal := Signal new. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
135 |
'nesting deeply'. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
136 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
137 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
138 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
139 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
140 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
141 |
Signal noHandlerSignal handle:[:ex | |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
142 |
ex proceedWith:nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
143 |
] do:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
144 |
(signal raise) == true ifTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
145 |
Transcript showCR:'query says: ok'. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
146 |
] ifFalse:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
147 |
Transcript showCR:'query says: no' |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
148 |
] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
149 |
] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
150 |
] value |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
151 |
] value |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
152 |
] value |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
153 |
] value |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
154 |
] value |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
155 |
[exEnd] |
4446 | 156 |
" |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
157 |
|
4446 | 158 |
! |
159 |
||
160 |
history |
|
161 |
"Created: / 23.7.1999 / 14:16:16 / stefan" |
|
162 |
! ! |
|
163 |
||
164 |
!Query class methodsFor:'answering queries'! |
|
165 |
||
166 |
answer:someAnswer do:aBlock |
|
167 |
"evaluate the argument, aBlock. |
|
168 |
If the receiver is queried during evaluation, answer with someAnswer. |
|
169 |
This is a wrapper for #handle:do: for lazy typists; no new functionality." |
|
170 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
171 |
thisContext markForHandle. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
172 |
aBlock value. |
4446 | 173 |
|
174 |
" |
|
175 |
Query answer:true do:[ |
|
176 |
Transcript showCR:'query answers: ' , (Query query printString). |
|
177 |
] |
|
178 |
" |
|
179 |
||
180 |
" |
|
181 |
Query answer:false do:[ |
|
182 |
Transcript showCR:'first query answers: ' , (Query query printString). |
|
183 |
Query answer:true do:[ |
|
184 |
Transcript showCR:'second query answers: ' , (Query query printString). |
|
185 |
] |
|
186 |
] |
|
187 |
" |
|
188 |
||
189 |
"Created: / 10.7.1996 / 15:08:20 / cg" |
|
190 |
"Modified: / 14.10.1996 / 16:59:18 / cg" |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
191 |
"Modified: / 25.7.1999 / 23:12:19 / stefan" |
4446 | 192 |
! ! |
193 |
||
194 |
!Query class methodsFor:'queries'! |
|
195 |
||
196 |
accepts:aSignal |
|
197 |
"return true, if the receiver accepts the argument, aSignal. |
|
198 |
(i.e. the receiver is aSignal or a parent of it). False otherwise." |
|
199 |
||
200 |
|s| |
|
201 |
||
202 |
aSignal isQuerySignal ifFalse:[^ false]. |
|
203 |
||
204 |
s := aSignal. |
|
205 |
[s notNil] whileTrue:[ |
|
206 |
self == s ifTrue:[^ true]. |
|
207 |
s := s parent |
|
208 |
]. |
|
209 |
^ false |
|
210 |
||
211 |
"Modified: / 22.3.1999 / 12:45:32 / stefan" |
|
212 |
"Created: / 23.7.1999 / 15:18:00 / stefan" |
|
213 |
! |
|
214 |
||
215 |
defaultAnswer |
|
216 |
"Return the default answer to the Query. This method is called, |
|
217 |
if nobody catches the signal. |
|
218 |
||
219 |
Subclasses may redefine this method." |
|
220 |
||
221 |
"Calling raiseRequest here will execute the exception's action method" |
|
222 |
||
223 |
^ super raiseRequest |
|
224 |
||
225 |
"Created: / 23.7.1999 / 15:16:03 / stefan" |
|
226 |
! |
|
227 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
228 |
handlerForSignal:signal context:theContext originator:originator |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
229 |
"answer the handler block for the signal from originator. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
230 |
The block is retrieved from aContext. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
231 |
Answer nil if the signal is not handled" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
232 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
233 |
|arg| |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
234 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
235 |
theContext selector == #'answer:do:' ifTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
236 |
(self accepts:signal) ifTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
237 |
arg := theContext argAt:1. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
238 |
^ [:ex| ex proceedWith:arg]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
239 |
] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
240 |
] ifFalse:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
241 |
^ super handlerForSignal:signal context:theContext originator:originator. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
242 |
]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
243 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
244 |
^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
245 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
246 |
"Created: / 25.7.1999 / 23:11:55 / stefan" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
247 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
248 |
|
4446 | 249 |
isQuerySignal |
250 |
||
251 |
^ true |
|
252 |
||
253 |
"Created: / 23.7.1999 / 14:59:50 / stefan" |
|
254 |
! |
|
255 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
256 |
query |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
257 |
"raise the query - return the handlers value, or the default |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
258 |
value, if there is no handler. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
259 |
Invoking the handler is exactly the functionality of Signal>>raiseRequest, |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
260 |
but we can do it faster here." |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
261 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
262 |
|con s| |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
263 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
264 |
con := thisContext sender. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
265 |
[con notNil] whileTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
266 |
con := con findSpecialHandle:true raise:true. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
267 |
con notNil ifTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
268 |
(con selector == #answer:do:) ifFalse:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
269 |
^ super raiseRequest |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
270 |
]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
271 |
(s := con receiver) == self ifTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
272 |
^ con argAt:1 |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
273 |
] ifFalse:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
274 |
(s accepts:self) ifTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
275 |
^ super raiseRequest |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
276 |
] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
277 |
] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
278 |
] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
279 |
]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
280 |
"/ no handler found - return the default value |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
281 |
^ self defaultAnswer |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
282 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
283 |
"Modified: / 15.6.1998 / 21:27:37 / cg" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
284 |
"Modified: / 25.7.1999 / 23:15:16 / stefan" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
285 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
286 |
|
4446 | 287 |
raise |
288 |
"QuerySignals are proceedable by definition, |
|
289 |
so they should be raised with #query or #raiseRequest" |
|
290 |
||
291 |
^ self shouldNotImplement |
|
292 |
||
293 |
"Created: / 23.7.1999 / 15:19:17 / stefan" |
|
294 |
! |
|
295 |
||
296 |
raiseRequest |
|
297 |
"redefined to use #query" |
|
298 |
||
299 |
^ self query |
|
300 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
301 |
"Created: / 25.7.1999 / 23:25:59 / stefan" |
4446 | 302 |
! ! |
303 |
||
304 |
!Query methodsFor:'default actions'! |
|
305 |
||
306 |
action |
|
307 |
"the default action is to return the default value. |
|
308 |
Subclasses may redefine this" |
|
309 |
||
310 |
^ nil |
|
311 |
||
312 |
"Modified: / 23.7.1999 / 15:13:34 / stefan" |
|
313 |
! ! |
|
314 |
||
315 |
!Query class methodsFor:'documentation'! |
|
316 |
||
317 |
version |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4446
diff
changeset
|
318 |
^ '$Header: /cvs/stx/stx/libbasic/Query.st,v 1.2 1999-07-28 07:53:26 stefan Exp $' |
4446 | 319 |
! ! |