author | Stefan Vogel <sv@exept.de> |
Fri, 23 Mar 2001 14:43:18 +0100 | |
changeset 5836 | e8265b824b8f |
parent 4547 | 082a2f7d9d8e |
child 6396 | 74d5b0b588a6 |
permissions | -rw-r--r-- |
1 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
159 | 3 |
All Rights Reserved |
1 | 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 |
||
5836
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
13 |
"{ Package: 'stx:libbasic' }" |
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
14 |
|
1 | 15 |
IdentitySet subclass:#SignalSet |
1275 | 16 |
instanceVariableNames:'' |
17 |
classVariableNames:'SetOfAnySignal' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Kernel-Exceptions' |
|
1 | 20 |
! |
21 |
||
44 | 22 |
!SignalSet class methodsFor:'documentation'! |
23 |
||
88 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
159 | 27 |
All Rights Reserved |
88 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
44 | 38 |
documentation |
39 |
" |
|
71 | 40 |
SignalSet allows catching of multiple signals. A SignalSet consists of |
95 | 41 |
a number of signals and also implements the #handle:do: and #catch: methods |
42 |
just as signals do. |
|
43 |
However, any signal from the SignalSet will, if signalled, lead into the handler. |
|
159 | 44 |
|
71 | 45 |
There is also a special signalSet, which can be used to catch any |
159 | 46 |
signal in the system - but this should no longer be used, since catching |
47 |
Object>>errorSignal has now the same effect. |
|
1 | 48 |
|
71 | 49 |
For more detail, see comment in Signal and examples in doc/coding. |
95 | 50 |
|
159 | 51 |
Notice: SignalSets are not needed when a group of children of a common signal |
52 |
(such as arithmeticSignal) is to be handled; the parent signal of those will |
|
53 |
also handle all children. |
|
54 |
Use signalSets if totally unrelated signals should be handled by one common |
|
55 |
handler. |
|
1275 | 56 |
|
57 |
||
1292 | 58 |
[author:] |
59 |
Claus Gittinger |
|
60 |
||
1275 | 61 |
[see also:] |
62 |
Exception |
|
63 |
Signal QuerySignal |
|
64 |
Object |
|
44 | 65 |
" |
66 |
! ! |
|
1 | 67 |
|
68 |
!SignalSet class methodsFor:'instance creation'! |
|
69 |
||
70 |
anySignal |
|
159 | 71 |
"return a special signalSet for catching any signal. |
2283 | 72 |
Questionable: |
73 |
you should use 'Object>>errorSignal' for that purpose; |
|
74 |
however, the anySignal-set also catches nonChilds of the ErrorSignal |
|
75 |
(i.e. highly private, strange signals)." |
|
1 | 76 |
|
44 | 77 |
SetOfAnySignal isNil ifTrue:[ |
2283 | 78 |
SetOfAnySignal := self basicNew |
44 | 79 |
]. |
80 |
^ SetOfAnySignal |
|
2283 | 81 |
|
82 |
"Modified: 27.1.1997 / 20:31:08 / cg" |
|
1 | 83 |
! ! |
84 |
||
5836
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
85 |
!SignalSet methodsFor:'adding'! |
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
86 |
|
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
87 |
, anException |
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
88 |
"add anException to the set" |
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
89 |
|
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
90 |
self add:anException |
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
91 |
! ! |
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
92 |
|
622 | 93 |
!SignalSet methodsFor:'queries'! |
94 |
||
95 |
accepts:aSignal |
|
96 |
"return true, if the receiver accepts the argument, aSignal. |
|
97 |
(i.e. if any of the receivers elements is aSignal or a parent of it). |
|
98 |
False otherwise. The special anySet accepts any (non-query) signal." |
|
99 |
||
100 |
(self == SetOfAnySignal) ifTrue:[^ aSignal isQuerySignal not]. |
|
4512 | 101 |
self do:[:sig | (sig == aSignal or:[sig accepts:aSignal]) ifTrue:[^ true]]. |
622 | 102 |
^ false |
103 |
! |
|
104 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
105 |
handlerForSignal:signal context:theContext originator:originator |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
106 |
"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:
3311
diff
changeset
|
107 |
The block is retrieved from aContext. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
108 |
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:
3311
diff
changeset
|
109 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
110 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
111 |
(theContext selector ~~ #'handle:from:do:' |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
112 |
or:[(theContext argAt:2) == originator]) ifTrue:[ |
4512 | 113 |
(self == signal or:[self accepts:signal]) ifTrue:[ |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
114 |
^ theContext argAt:1 |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
115 |
] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
116 |
]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
117 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
118 |
^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
119 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
120 |
"Created: / 25.7.1999 / 23:46:48 / stefan" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
121 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
122 |
|
4545
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
123 |
handlerProtectedBlock:doBlock inContext:context |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
124 |
"set the handlerProtectedBlock in context" |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
125 |
|
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
126 |
context selector == #handle:do: ifTrue:[ |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
127 |
context argAt:2 put:doBlock. |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
128 |
] ifFalse:[context selector == #handle:from:do: ifTrue:[ |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
129 |
context argAt:3 put:doBlock. |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
130 |
]]. |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
131 |
|
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
132 |
" |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
133 |
SignalSet anySignal |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
134 |
handle:[:ex| ex restartDo:[55]] do:[1 // 0] |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
135 |
" |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
136 |
|
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
137 |
|
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
138 |
"Created: / 25.7.1999 / 23:46:48 / stefan" |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
139 |
! |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
140 |
|
4475 | 141 |
handlingExceptionInContext:theContext |
142 |
"answer the handling signalSet from aContext." |
|
4473
793078981f01
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4465
diff
changeset
|
143 |
|
793078981f01
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4465
diff
changeset
|
144 |
^ self |
793078981f01
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4465
diff
changeset
|
145 |
|
793078981f01
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4465
diff
changeset
|
146 |
! |
793078981f01
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4465
diff
changeset
|
147 |
|
622 | 148 |
includes:aSignal |
149 |
"return true, if the receiver contains the argument, aSignal. |
|
150 |
The special any-Set includes every (non-query) signal." |
|
151 |
||
152 |
(self == SetOfAnySignal) ifTrue:[ |
|
153 |
^ (aSignal isSignal and:[aSignal isQuerySignal not]) |
|
154 |
]. |
|
155 |
^ super includes:aSignal |
|
156 |
! ! |
|
157 |
||
1 | 158 |
!SignalSet methodsFor:'save evaluation'! |
159 |
||
622 | 160 |
catch:aBlock |
161 |
"evaluate the argument, aBlock. |
|
162 |
If any of the signals in the receiver is raised during evaluation, |
|
163 |
abort the evaluation and return true; otherwise return false. |
|
164 |
With the special anySignal, evaluation can be performed totally save |
|
165 |
from signals |
|
166 |
- but who (beside radical c++ fans) would do that ?" |
|
167 |
||
168 |
|raiseOccurred| |
|
169 |
||
170 |
raiseOccurred := false. |
|
171 |
self handle:[:ex | raiseOccurred := true. ex return] do:aBlock. |
|
172 |
^ raiseOccurred |
|
173 |
||
174 |
" |
|
175 |
SignalSet anySignal catch:[ |
|
176 |
(#(1 2 3 4) at:5) / 0.0 |
|
177 |
] |
|
178 |
" |
|
179 |
! |
|
180 |
||
1 | 181 |
handle:handleBlock do:aBlock |
182 |
"evaluate the argument, aBlock. |
|
183 |
If any of the signals in the receiver is raised during evaluation, |
|
184 |
evaluate the handleBlock passing it an Exception argument. |
|
185 |
The handler may decide how to react to the signal by sending |
|
186 |
a corresponding message to the exception (see there). |
|
187 |
If the signal is not raised, return the value of evaluating |
|
188 |
aBlock." |
|
189 |
||
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4545
diff
changeset
|
190 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
191 |
<exception: #handle> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
192 |
|
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
193 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
194 |
^ aBlock value "the real logic is in Exception>>doRaise" |
95 | 195 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
196 |
" |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
197 |
SignalSet anySignal handle:[:ex | |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
198 |
ex errorString print. ' occured in: ' print. ex suspendedContext printNL. |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
199 |
ex return |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
200 |
] do:[ |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
201 |
(#(1 2 3 4) at:5) / 0.0 |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
202 |
] |
4465 | 203 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
204 |
SignalSet anySignal handle:[:ex | |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
205 |
ex errorString print. ' occured in: ' print. ex suspendedContext printNL. |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
206 |
self bar. |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
207 |
ex return |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
208 |
] do:[ |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
209 |
(#(1 2 3 4) at:5) / 0.0 |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
210 |
] |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
211 |
" |
3308 | 212 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
213 |
"Modified: / 26.7.1999 / 00:03:13 / stefan" |
44 | 214 |
! |
215 |
||
362 | 216 |
handle:handleBlock from:anObject do:aBlock |
217 |
"evaluate the argument, aBlock. |
|
218 |
If any of the signals in the receiver is raised during evaluation, |
|
219 |
and the exception originated from anObject, |
|
220 |
evaluate the handleBlock passing it an Exception argument. |
|
221 |
The handler may decide how to react to the signal by sending |
|
222 |
a corresponding message to the exception (see there). |
|
223 |
If the signal is not raised, return the value of evaluating |
|
224 |
aBlock." |
|
225 |
||
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4545
diff
changeset
|
226 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
227 |
<exception: #handle> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
228 |
|
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
229 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
230 |
^ aBlock value "the real logic is in Exception>>doRaise" |
3308 | 231 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
232 |
"Modified: / 26.7.1999 / 00:03:06 / stefan" |
362 | 233 |
! |
234 |
||
2284
8b29d42bb03d
oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents:
2283
diff
changeset
|
235 |
ignoreIn:aBlock |
159 | 236 |
"evaluate the argument, aBlock. |
2284
8b29d42bb03d
oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents:
2283
diff
changeset
|
237 |
Ignore the any signals from the receiver during evaluation - i.e. simply |
159 | 238 |
continue. This makes only sense for some signals, such as UserInterrupt |
239 |
or AbortSignals, because continuing after an exception without any cleanup |
|
240 |
will often lead to followup-errors." |
|
241 |
||
4486
f84def7aaf3f
replaced #proceed with #proceedWith:nil
Claus Gittinger <cg@exept.de>
parents:
4475
diff
changeset
|
242 |
^ self handle:[:ex | ex proceedWith:nil] do:aBlock. |
159 | 243 |
|
244 |
" |
|
3311 | 245 |
SignalSet anySignal ignoreIn:[ |
2284
8b29d42bb03d
oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents:
2283
diff
changeset
|
246 |
123 size open |
95 | 247 |
] |
248 |
" |
|
2284
8b29d42bb03d
oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents:
2283
diff
changeset
|
249 |
|
3311 | 250 |
"Created: / 27.1.1997 / 20:32:50 / cg" |
251 |
"Modified: / 4.3.1998 / 16:36:30 / cg" |
|
1 | 252 |
! ! |
253 |
||
696 | 254 |
!SignalSet class methodsFor:'documentation'! |
255 |
||
256 |
version |
|
5836
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
257 |
^ '$Header: /cvs/stx/stx/libbasic/SignalSet.st,v 1.34 2001-03-23 13:43:18 stefan Exp $' |
696 | 258 |
! ! |