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