author | Claus Gittinger <cg@exept.de> |
Thu, 27 Jun 2019 15:21:18 +0200 | |
changeset 24377 | 2fbcb2fa6c43 |
parent 23885 | 00e1469e8704 |
child 25089 | 97cb83e058e2 |
permissions | -rw-r--r-- |
23301 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1 | 3 |
" |
4 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
159 | 5 |
All Rights Reserved |
1 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
5836
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
14 |
"{ Package: 'stx:libbasic' }" |
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
15 |
|
19445 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
1 | 18 |
IdentitySet subclass:#SignalSet |
1275 | 19 |
instanceVariableNames:'' |
15064 | 20 |
classVariableNames:'' |
1275 | 21 |
poolDictionaries:'' |
22 |
category:'Kernel-Exceptions' |
|
1 | 23 |
! |
24 |
||
15064 | 25 |
SignalSet subclass:#SetOfAnySignal |
26 |
instanceVariableNames:'' |
|
27 |
classVariableNames:'' |
|
28 |
poolDictionaries:'' |
|
29 |
privateIn:SignalSet |
|
30 |
! |
|
31 |
||
32 |
SignalSet::SetOfAnySignal class instanceVariableNames:'theOneAndOnlyInstance' |
|
33 |
||
34 |
" |
|
35 |
No other class instance variables are inherited by this class. |
|
36 |
" |
|
37 |
! |
|
38 |
||
44 | 39 |
!SignalSet class methodsFor:'documentation'! |
40 |
||
88 | 41 |
copyright |
42 |
" |
|
43 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
159 | 44 |
All Rights Reserved |
88 | 45 |
|
46 |
This software is furnished under a license and may be used |
|
47 |
only in accordance with the terms of that license and with the |
|
48 |
inclusion of the above copyright notice. This software may not |
|
49 |
be provided or otherwise made available to, or used by, any |
|
50 |
other person. No title to or ownership of the software is |
|
51 |
hereby transferred. |
|
52 |
" |
|
53 |
! |
|
54 |
||
44 | 55 |
documentation |
56 |
" |
|
71 | 57 |
SignalSet allows catching of multiple signals. A SignalSet consists of |
95 | 58 |
a number of signals and also implements the #handle:do: and #catch: methods |
16562 | 59 |
just as signals do. |
95 | 60 |
However, any signal from the SignalSet will, if signalled, lead into the handler. |
159 | 61 |
|
71 | 62 |
There is also a special signalSet, which can be used to catch any |
159 | 63 |
signal in the system - but this should no longer be used, since catching |
64 |
Object>>errorSignal has now the same effect. |
|
1 | 65 |
|
71 | 66 |
For more detail, see comment in Signal and examples in doc/coding. |
95 | 67 |
|
159 | 68 |
Notice: SignalSets are not needed when a group of children of a common signal |
69 |
(such as arithmeticSignal) is to be handled; the parent signal of those will |
|
70 |
also handle all children. |
|
71 |
Use signalSets if totally unrelated signals should be handled by one common |
|
72 |
handler. |
|
1275 | 73 |
|
74 |
||
1292 | 75 |
[author:] |
16562 | 76 |
Claus Gittinger |
1292 | 77 |
|
1275 | 78 |
[see also:] |
16562 | 79 |
Exception |
80 |
Signal QuerySignal |
|
81 |
Object |
|
44 | 82 |
" |
83 |
! ! |
|
1 | 84 |
|
85 |
!SignalSet class methodsFor:'instance creation'! |
|
86 |
||
87 |
anySignal |
|
159 | 88 |
"return a special signalSet for catching any signal. |
2283 | 89 |
Questionable: |
16562 | 90 |
you should use 'Object>>errorSignal' for that purpose; |
91 |
however, the anySignal-set also catches nonChilds of the ErrorSignal |
|
92 |
(i.e. highly private, strange signals)." |
|
1 | 93 |
|
15064 | 94 |
^ SetOfAnySignal new |
2283 | 95 |
|
96 |
"Modified: 27.1.1997 / 20:31:08 / cg" |
|
1 | 97 |
! ! |
98 |
||
23885 | 99 |
|
5836
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
100 |
!SignalSet methodsFor:'adding'! |
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
101 |
|
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
102 |
, anException |
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
103 |
"add anException to the set" |
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
104 |
|
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
105 |
self add:anException |
15064 | 106 |
! |
107 |
||
108 |
add:anExceptionHandler |
|
109 |
"Check, that only exceptionHandlers are added. |
|
110 |
Very bad (recursive) things may happen if e.g. #accepts: is called |
|
111 |
and raises a MessageNotUnderstood error." |
|
112 |
||
113 |
anExceptionHandler isExceptionHandler ifFalse:[ |
|
16562 | 114 |
SignalError raiseWith:anExceptionHandler errorString:' - trying to add a non-exceptionHandler to a SignalSet'. |
15064 | 115 |
]. |
116 |
^ super add:anExceptionHandler. |
|
5836
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
117 |
! ! |
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
118 |
|
622 | 119 |
!SignalSet methodsFor:'queries'! |
120 |
||
23301 | 121 |
accepts:aSignalOrExceptionClass |
622 | 122 |
"return true, if the receiver accepts the argument, aSignal. |
19445 | 123 |
(i.e. if any of the receiver's elements is aSignal or a parent of it). |
15064 | 124 |
False otherwise." |
622 | 125 |
|
16562 | 126 |
self do:[:eachExceptionHandler | |
23301 | 127 |
(eachExceptionHandler==aSignalOrExceptionClass |
128 |
or:[eachExceptionHandler accepts:aSignalOrExceptionClass]) ifTrue:[^ true]. |
|
8681
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
129 |
]. |
622 | 130 |
^ false |
23301 | 131 |
|
132 |
"Modified (format): / 28-08-2018 / 11:16:49 / Claus Gittinger" |
|
622 | 133 |
! |
134 |
||
8681
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
135 |
exceptionHandlerFor:anException in:aContext |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
136 |
"answer the exceptionHandler for anException from aContext." |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
137 |
|
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
138 |
^ self |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
139 |
! |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
140 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
141 |
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
|
142 |
"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
|
143 |
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
|
144 |
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
|
145 |
|
8699
ed6792665e78
Care for #answer:do: handlers. Must proceed.
Stefan Vogel <sv@exept.de>
parents:
8696
diff
changeset
|
146 |
|selector arg| |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
147 |
|
8699
ed6792665e78
Care for #answer:do: handlers. Must proceed.
Stefan Vogel <sv@exept.de>
parents:
8696
diff
changeset
|
148 |
selector := theContext selector. |
ed6792665e78
Care for #answer:do: handlers. Must proceed.
Stefan Vogel <sv@exept.de>
parents:
8696
diff
changeset
|
149 |
(selector ~~ #'handle:from:do:' |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
150 |
or:[(theContext argAt:2) == originator]) ifTrue:[ |
16562 | 151 |
(self == signal or:[self accepts:signal]) ifTrue:[ |
152 |
arg := theContext argAt:1. |
|
153 |
selector == #answer:do: ifTrue:[ |
|
154 |
^ [:ex| ex proceedWith:arg]. |
|
155 |
] ifFalse:[ |
|
156 |
^ arg ? [nil]. |
|
157 |
]. |
|
158 |
] |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
159 |
]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
160 |
^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
161 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
162 |
"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
|
163 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
164 |
|
4545
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
165 |
handlerProtectedBlock:doBlock inContext:context |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
166 |
"set the handlerProtectedBlock in context" |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
167 |
|
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
168 |
context selector == #handle:do: ifTrue:[ |
16562 | 169 |
context argAt:2 put:doBlock. |
4545
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
170 |
] ifFalse:[context selector == #handle:from:do: ifTrue:[ |
16562 | 171 |
context argAt:3 put:doBlock. |
4545
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
172 |
]]. |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
173 |
|
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
174 |
" |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
175 |
SignalSet anySignal |
16562 | 176 |
handle:[:ex| ex restartDo:[55]] do:[1 // 0] |
4545
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
177 |
" |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
178 |
|
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
179 |
|
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
180 |
"Created: / 25.7.1999 / 23:46:48 / stefan" |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
181 |
! |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
182 |
|
8681
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
183 |
handles:anException |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
184 |
"return true, if the receiver handles the argument, anException. |
19445 | 185 |
(i.e. if any of the receiver's elements handles anException)." |
4473
793078981f01
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4465
diff
changeset
|
186 |
|
16562 | 187 |
self do:[:eachExceptionHandler| |
19445 | 188 |
(eachExceptionHandler handles:anException) ifTrue:[^ true] |
8681
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
189 |
]. |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
190 |
^ false |
4473
793078981f01
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4465
diff
changeset
|
191 |
! |
793078981f01
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4465
diff
changeset
|
192 |
|
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6518
diff
changeset
|
193 |
isExceptionHandler |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6518
diff
changeset
|
194 |
"return true, if the receiver responds to the exception handler protocol, |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6518
diff
changeset
|
195 |
especially to the #accepts: and #handles: messages" |
6518 | 196 |
|
197 |
^ true |
|
622 | 198 |
! ! |
199 |
||
1 | 200 |
!SignalSet methodsFor:'save evaluation'! |
201 |
||
8689
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
202 |
answer:someAnswer do:aBlock |
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
203 |
"evaluate the argument, aBlock. |
12063 | 204 |
If the receiver is queried during evaluation, answer and proceed with someAnswer. |
8689
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
205 |
This is a wrapper for #handle:do: for lazy typists; no new functionality." |
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
206 |
|
8696
fd361ae49596
#answer:do: must be returnable (see last change)
Stefan Vogel <sv@exept.de>
parents:
8689
diff
changeset
|
207 |
<context: #return> |
8689
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
208 |
<exception: #handle> |
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
209 |
|
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
210 |
"/ thisContext markForHandle. -- same as above pragma |
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
211 |
^ aBlock value. "the real logic is in Exception>>doRaise" |
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
212 |
! |
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
213 |
|
622 | 214 |
catch:aBlock |
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
215 |
"evaluate the argument, aBlock. |
16562 | 216 |
If any of the signals in the receiver is raised during evaluation, |
217 |
abort the evaluation and return true; otherwise return false. |
|
218 |
With the special anySignal, evaluation can be performed totally save |
|
9079 | 219 |
from signals - but who (beside radical c++ fans) would do that ?" |
220 |
||
221 |
|raiseOccurred| |
|
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
222 |
|
9079 | 223 |
raiseOccurred := false. |
224 |
self handle:[:ex | raiseOccurred := true. ex return] do:aBlock. |
|
225 |
^ raiseOccurred |
|
622 | 226 |
|
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
227 |
" |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
228 |
SignalSet anySignal catch:[ |
16562 | 229 |
(#(1 2 3 4) at:5) / 0.0 |
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
230 |
] |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
231 |
" |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
232 |
! |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
233 |
|
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
234 |
deferAfter:aBlock |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
235 |
"evaluate the argument, aBlock. |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
236 |
Ignore the receiver-signal during evaluation - i.e. simply continue, |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
237 |
but remember if the signal was raised. |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
238 |
After the block evaluation, finally raise the signal - if it was raised in the block. |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
239 |
If the signal is raised multiple times, only the first raises parameter is remembered, |
23885 | 240 |
and only a single raise is performed after the block's evaluation. |
622 | 241 |
|
16562 | 242 |
Deferring makes sense for some signals, such as UserInterrupt or AbortSignal, |
243 |
which must occasionally be delayed temprarily until a save place is reached |
|
20821 | 244 |
(especially when packages are sent across a communication channel, and you don't want |
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
245 |
partial packages to be generated by user interruptions)." |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
246 |
|
16562 | 247 |
|caughtException result| |
622 | 248 |
|
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
249 |
self handle:[:ex | |
20821 | 250 |
caughtException isNil ifTrue:[ |
251 |
caughtException := ex. |
|
252 |
]. |
|
253 |
ex proceedWith:nil |
|
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
254 |
] do:[ |
20821 | 255 |
result := aBlock value. |
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
256 |
]. |
16562 | 257 |
caughtException notNil ifTrue:[ |
20821 | 258 |
caughtException suspendedContext:thisContext. |
6428
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
259 |
|
20821 | 260 |
"/ a signal was raised during the execution of aBlock above. |
261 |
"/ Raise it now (delayed). |
|
262 |
caughtException raiseSignal |
|
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
263 |
]. |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
264 |
^ result |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
265 |
|
6428
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
266 |
" |
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
267 |
(UserInterrupt , AbortOperationRequest) deferAfter:[ |
20821 | 268 |
Transcript showCR:'1 - now raising, but will be deferred.'. |
269 |
UserInterrupt raiseRequestWith:'hello'. |
|
270 |
Transcript showCR:'2 - after the raise, deferred exception will be handled soon.'. |
|
6428
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
271 |
]. |
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
272 |
Transcript showCR:'3 - here after the protected block.'. |
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
273 |
" |
23885 | 274 |
|
275 |
"Modified (comment): / 13-03-2019 / 10:28:12 / Claus Gittinger" |
|
622 | 276 |
! |
277 |
||
1 | 278 |
handle:handleBlock do:aBlock |
279 |
"evaluate the argument, aBlock. |
|
280 |
If any of the signals in the receiver is raised during evaluation, |
|
281 |
evaluate the handleBlock passing it an Exception argument. |
|
282 |
The handler may decide how to react to the signal by sending |
|
283 |
a corresponding message to the exception (see there). |
|
284 |
If the signal is not raised, return the value of evaluating |
|
285 |
aBlock." |
|
286 |
||
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4545
diff
changeset
|
287 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
288 |
<exception: #handle> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
289 |
|
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
290 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
291 |
^ aBlock value "the real logic is in Exception>>doRaise" |
95 | 292 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
293 |
" |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
294 |
SignalSet anySignal handle:[:ex | |
20250 | 295 |
ex errorString print. ' occurred in: ' print. ex suspendedContext printNL. |
296 |
ex return |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
297 |
] do:[ |
20250 | 298 |
(#(1 2 3 4) at:5) / 0.0 |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
299 |
] |
4465 | 300 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
301 |
SignalSet anySignal handle:[:ex | |
20250 | 302 |
ex errorString print. ' occurred in: ' print. ex suspendedContext printNL. |
303 |
self bar. |
|
304 |
ex return |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
305 |
] do:[ |
20250 | 306 |
(#(1 2 3 4) at:5) / 0.0 |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
307 |
] |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
308 |
" |
3308 | 309 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
310 |
"Modified: / 26.7.1999 / 00:03:13 / stefan" |
44 | 311 |
! |
312 |
||
362 | 313 |
handle:handleBlock from:anObject do:aBlock |
314 |
"evaluate the argument, aBlock. |
|
315 |
If any of the signals in the receiver is raised during evaluation, |
|
316 |
and the exception originated from anObject, |
|
317 |
evaluate the handleBlock passing it an Exception argument. |
|
318 |
The handler may decide how to react to the signal by sending |
|
319 |
a corresponding message to the exception (see there). |
|
320 |
If the signal is not raised, return the value of evaluating |
|
321 |
aBlock." |
|
322 |
||
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4545
diff
changeset
|
323 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
324 |
<exception: #handle> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
325 |
|
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
326 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
327 |
^ aBlock value "the real logic is in Exception>>doRaise" |
3308 | 328 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
329 |
"Modified: / 26.7.1999 / 00:03:06 / stefan" |
362 | 330 |
! |
331 |
||
2284
8b29d42bb03d
oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents:
2283
diff
changeset
|
332 |
ignoreIn:aBlock |
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
333 |
"evaluate the argument, aBlock. |
21854 | 334 |
Ignore any signal from the receiver during evaluation - i.e. simply continue with the default resume value. |
335 |
This makes only sense for some signals, such as UserInterrupt |
|
21566 | 336 |
or AbortOperationRequest, because continuing after an exception without any cleanup |
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
337 |
will often lead to followup-errors." |
159 | 338 |
|
21854 | 339 |
^ self handle:[:ex | ex proceed] do:aBlock. |
159 | 340 |
|
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
341 |
" |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
342 |
SignalSet anySignal ignoreIn:[ |
21566 | 343 |
123 size open |
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
344 |
] |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
345 |
" |
2284
8b29d42bb03d
oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents:
2283
diff
changeset
|
346 |
|
21566 | 347 |
"Created: / 27-01-1997 / 20:32:50 / cg" |
348 |
"Modified (comment): / 24-02-2017 / 11:15:59 / stefan" |
|
21854 | 349 |
"Modified (comment): / 20-06-2017 / 13:35:43 / cg" |
1 | 350 |
! ! |
351 |
||
15064 | 352 |
!SignalSet::SetOfAnySignal class methodsFor:'instance creation'! |
353 |
||
354 |
flushSingleton |
|
355 |
"flushes the cached singleton" |
|
356 |
||
357 |
theOneAndOnlyInstance := nil |
|
358 |
||
359 |
" |
|
360 |
self flushSingleton |
|
361 |
" |
|
362 |
! |
|
363 |
||
364 |
new |
|
365 |
"returns a singleton" |
|
366 |
||
367 |
^ self theOneAndOnlyInstance. |
|
368 |
! |
|
369 |
||
370 |
theOneAndOnlyInstance |
|
371 |
"returns a singleton" |
|
372 |
||
373 |
theOneAndOnlyInstance isNil ifTrue:[ |
|
16562 | 374 |
theOneAndOnlyInstance := self basicNew initialize. |
15064 | 375 |
]. |
376 |
^ theOneAndOnlyInstance. |
|
377 |
! ! |
|
378 |
||
379 |
!SignalSet::SetOfAnySignal methodsFor:'blocked methods'! |
|
380 |
||
381 |
add:anElement |
|
382 |
"do not allow to add anything" |
|
383 |
||
384 |
^ self shouldNotImplement |
|
385 |
! ! |
|
386 |
||
387 |
!SignalSet::SetOfAnySignal methodsFor:'queries'! |
|
388 |
||
23301 | 389 |
accepts:aSignalOrExceptionClass |
15064 | 390 |
"return true, if the receiver accepts the argument, aSignal. |
19445 | 391 |
(i.e. if any of the receiver's elements is aSignal or a parent of it). |
15064 | 392 |
False otherwise. I, the special SetOfAnySignal accepts any (non-query) signal." |
393 |
||
23301 | 394 |
^ aSignalOrExceptionClass isExceptionHandler and:[aSignalOrExceptionClass isQuerySignal not] |
395 |
||
396 |
"Modified (format): / 28-08-2018 / 11:16:55 / Claus Gittinger" |
|
15064 | 397 |
! |
398 |
||
399 |
handles:anException |
|
400 |
"return true, if the receiver handles the argument, anException. |
|
19445 | 401 |
(i.e. if any of the receiver's elements handles anException). |
15064 | 402 |
I, the special SetOfAnySignal handle any (non-query) signal." |
403 |
||
404 |
^ anException isNotification not |
|
405 |
! |
|
406 |
||
407 |
includes:anExceptionHandler |
|
408 |
"return true, if the receiver contains the argument, anExceptionHandler. |
|
409 |
I, the special SetOfAnySignal include any (non-query) ExceptionHandler." |
|
410 |
||
411 |
^ anExceptionHandler isExceptionHandler and:[anExceptionHandler isQuerySignal not] |
|
412 |
! ! |
|
413 |
||
696 | 414 |
!SignalSet class methodsFor:'documentation'! |
415 |
||
416 |
version |
|
19445 | 417 |
^ '$Header$' |
12063 | 418 |
! |
419 |
||
420 |
version_CVS |
|
19445 | 421 |
^ '$Header$' |
696 | 422 |
! ! |
19445 | 423 |