author | Stefan Vogel <sv@exept.de> |
Mon, 09 Dec 2019 11:20:44 +0100 | |
changeset 25089 | 97cb83e058e2 |
parent 23885 | 00e1469e8704 |
child 25355 | abe090376550 |
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 |
|
25089 | 102 |
, anExceptionHandler |
103 |
"add anExceptionHandler to the set" |
|
5836
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
104 |
|
25089 | 105 |
self add:anExceptionHandler. |
106 |
||
107 |
"Modified: / 09-12-2019 / 11:09:05 / Stefan Vogel" |
|
15064 | 108 |
! |
109 |
||
110 |
add:anExceptionHandler |
|
111 |
"Check, that only exceptionHandlers are added. |
|
112 |
Very bad (recursive) things may happen if e.g. #accepts: is called |
|
113 |
and raises a MessageNotUnderstood error." |
|
114 |
||
25089 | 115 |
anExceptionHandler isNil ifTrue:[ |
116 |
"Ignore nil exceptionHandler - it may be due to a missing (not loaded) expception class" |
|
117 |
^ nil. |
|
118 |
]. |
|
15064 | 119 |
anExceptionHandler isExceptionHandler ifFalse:[ |
25089 | 120 |
SignalError raiseWith:anExceptionHandler errorString:' - trying to add a non-exceptionHandler to a SignalSet'. |
15064 | 121 |
]. |
122 |
^ super add:anExceptionHandler. |
|
25089 | 123 |
|
124 |
" |
|
125 |
SignalSet with:nil with:TimeoutError |
|
126 |
" |
|
127 |
||
128 |
"Modified: / 09-12-2019 / 11:08:56 / Stefan Vogel" |
|
5836
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
129 |
! ! |
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
130 |
|
622 | 131 |
!SignalSet methodsFor:'queries'! |
132 |
||
23301 | 133 |
accepts:aSignalOrExceptionClass |
622 | 134 |
"return true, if the receiver accepts the argument, aSignal. |
19445 | 135 |
(i.e. if any of the receiver's elements is aSignal or a parent of it). |
15064 | 136 |
False otherwise." |
622 | 137 |
|
16562 | 138 |
self do:[:eachExceptionHandler | |
23301 | 139 |
(eachExceptionHandler==aSignalOrExceptionClass |
140 |
or:[eachExceptionHandler accepts:aSignalOrExceptionClass]) ifTrue:[^ true]. |
|
8681
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
141 |
]. |
622 | 142 |
^ false |
23301 | 143 |
|
144 |
"Modified (format): / 28-08-2018 / 11:16:49 / Claus Gittinger" |
|
622 | 145 |
! |
146 |
||
8681
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
147 |
exceptionHandlerFor:anException in:aContext |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
148 |
"answer the exceptionHandler for anException from aContext." |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
149 |
|
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
150 |
^ self |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
151 |
! |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
152 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
153 |
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
|
154 |
"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
|
155 |
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
|
156 |
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
|
157 |
|
8699
ed6792665e78
Care for #answer:do: handlers. Must proceed.
Stefan Vogel <sv@exept.de>
parents:
8696
diff
changeset
|
158 |
|selector arg| |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
159 |
|
8699
ed6792665e78
Care for #answer:do: handlers. Must proceed.
Stefan Vogel <sv@exept.de>
parents:
8696
diff
changeset
|
160 |
selector := theContext selector. |
ed6792665e78
Care for #answer:do: handlers. Must proceed.
Stefan Vogel <sv@exept.de>
parents:
8696
diff
changeset
|
161 |
(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
|
162 |
or:[(theContext argAt:2) == originator]) ifTrue:[ |
16562 | 163 |
(self == signal or:[self accepts:signal]) ifTrue:[ |
164 |
arg := theContext argAt:1. |
|
165 |
selector == #answer:do: ifTrue:[ |
|
166 |
^ [:ex| ex proceedWith:arg]. |
|
167 |
] ifFalse:[ |
|
168 |
^ arg ? [nil]. |
|
169 |
]. |
|
170 |
] |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
171 |
]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
172 |
^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
173 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
174 |
"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
|
175 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
176 |
|
4545
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
177 |
handlerProtectedBlock:doBlock inContext:context |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
178 |
"set the handlerProtectedBlock in context" |
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 |
context selector == #handle:do: ifTrue:[ |
16562 | 181 |
context argAt:2 put:doBlock. |
4545
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
182 |
] ifFalse:[context selector == #handle:from:do: ifTrue:[ |
16562 | 183 |
context argAt:3 put:doBlock. |
4545
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
184 |
]]. |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
185 |
|
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
186 |
" |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
187 |
SignalSet anySignal |
16562 | 188 |
handle:[:ex| ex restartDo:[55]] do:[1 // 0] |
4545
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
189 |
" |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
190 |
|
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
191 |
|
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
192 |
"Created: / 25.7.1999 / 23:46:48 / stefan" |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
193 |
! |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
194 |
|
8681
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
195 |
handles:anException |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
196 |
"return true, if the receiver handles the argument, anException. |
19445 | 197 |
(i.e. if any of the receiver's elements handles anException)." |
4473
793078981f01
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4465
diff
changeset
|
198 |
|
16562 | 199 |
self do:[:eachExceptionHandler| |
19445 | 200 |
(eachExceptionHandler handles:anException) ifTrue:[^ true] |
8681
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
201 |
]. |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
202 |
^ false |
4473
793078981f01
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4465
diff
changeset
|
203 |
! |
793078981f01
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4465
diff
changeset
|
204 |
|
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6518
diff
changeset
|
205 |
isExceptionHandler |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6518
diff
changeset
|
206 |
"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
|
207 |
especially to the #accepts: and #handles: messages" |
6518 | 208 |
|
209 |
^ true |
|
622 | 210 |
! ! |
211 |
||
1 | 212 |
!SignalSet methodsFor:'save evaluation'! |
213 |
||
8689
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
214 |
answer:someAnswer do:aBlock |
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
215 |
"evaluate the argument, aBlock. |
12063 | 216 |
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
|
217 |
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
|
218 |
|
8696
fd361ae49596
#answer:do: must be returnable (see last change)
Stefan Vogel <sv@exept.de>
parents:
8689
diff
changeset
|
219 |
<context: #return> |
8689
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
220 |
<exception: #handle> |
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
221 |
|
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
222 |
"/ thisContext markForHandle. -- same as above pragma |
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
223 |
^ aBlock value. "the real logic is in Exception>>doRaise" |
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
224 |
! |
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
225 |
|
622 | 226 |
catch:aBlock |
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
227 |
"evaluate the argument, aBlock. |
16562 | 228 |
If any of the signals in the receiver is raised during evaluation, |
229 |
abort the evaluation and return true; otherwise return false. |
|
230 |
With the special anySignal, evaluation can be performed totally save |
|
9079 | 231 |
from signals - but who (beside radical c++ fans) would do that ?" |
232 |
||
233 |
|raiseOccurred| |
|
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
234 |
|
9079 | 235 |
raiseOccurred := false. |
236 |
self handle:[:ex | raiseOccurred := true. ex return] do:aBlock. |
|
237 |
^ raiseOccurred |
|
622 | 238 |
|
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
239 |
" |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
240 |
SignalSet anySignal catch:[ |
16562 | 241 |
(#(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
|
242 |
] |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
243 |
" |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
244 |
! |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
245 |
|
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
246 |
deferAfter:aBlock |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
247 |
"evaluate the argument, aBlock. |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
248 |
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
|
249 |
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
|
250 |
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
|
251 |
If the signal is raised multiple times, only the first raises parameter is remembered, |
23885 | 252 |
and only a single raise is performed after the block's evaluation. |
622 | 253 |
|
16562 | 254 |
Deferring makes sense for some signals, such as UserInterrupt or AbortSignal, |
255 |
which must occasionally be delayed temprarily until a save place is reached |
|
20821 | 256 |
(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
|
257 |
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
|
258 |
|
16562 | 259 |
|caughtException result| |
622 | 260 |
|
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
261 |
self handle:[:ex | |
20821 | 262 |
caughtException isNil ifTrue:[ |
263 |
caughtException := ex. |
|
264 |
]. |
|
265 |
ex proceedWith:nil |
|
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
266 |
] do:[ |
20821 | 267 |
result := aBlock value. |
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
268 |
]. |
16562 | 269 |
caughtException notNil ifTrue:[ |
20821 | 270 |
caughtException suspendedContext:thisContext. |
6428
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
271 |
|
20821 | 272 |
"/ a signal was raised during the execution of aBlock above. |
273 |
"/ Raise it now (delayed). |
|
274 |
caughtException raiseSignal |
|
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
275 |
]. |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
276 |
^ result |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
277 |
|
6428
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
278 |
" |
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
279 |
(UserInterrupt , AbortOperationRequest) deferAfter:[ |
20821 | 280 |
Transcript showCR:'1 - now raising, but will be deferred.'. |
281 |
UserInterrupt raiseRequestWith:'hello'. |
|
282 |
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
|
283 |
]. |
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
284 |
Transcript showCR:'3 - here after the protected block.'. |
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
285 |
" |
23885 | 286 |
|
287 |
"Modified (comment): / 13-03-2019 / 10:28:12 / Claus Gittinger" |
|
622 | 288 |
! |
289 |
||
1 | 290 |
handle:handleBlock do:aBlock |
291 |
"evaluate the argument, aBlock. |
|
292 |
If any of the signals in the receiver is raised during evaluation, |
|
293 |
evaluate the handleBlock passing it an Exception argument. |
|
294 |
The handler may decide how to react to the signal by sending |
|
295 |
a corresponding message to the exception (see there). |
|
296 |
If the signal is not raised, return the value of evaluating |
|
297 |
aBlock." |
|
298 |
||
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4545
diff
changeset
|
299 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
300 |
<exception: #handle> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
301 |
|
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
302 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
303 |
^ aBlock value "the real logic is in Exception>>doRaise" |
95 | 304 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
305 |
" |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
306 |
SignalSet anySignal handle:[:ex | |
20250 | 307 |
ex errorString print. ' occurred in: ' print. ex suspendedContext printNL. |
308 |
ex return |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
309 |
] do:[ |
20250 | 310 |
(#(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
|
311 |
] |
4465 | 312 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
313 |
SignalSet anySignal handle:[:ex | |
20250 | 314 |
ex errorString print. ' occurred in: ' print. ex suspendedContext printNL. |
315 |
self bar. |
|
316 |
ex return |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
317 |
] do:[ |
20250 | 318 |
(#(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
|
319 |
] |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
320 |
" |
3308 | 321 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
322 |
"Modified: / 26.7.1999 / 00:03:13 / stefan" |
44 | 323 |
! |
324 |
||
362 | 325 |
handle:handleBlock from:anObject do:aBlock |
326 |
"evaluate the argument, aBlock. |
|
327 |
If any of the signals in the receiver is raised during evaluation, |
|
328 |
and the exception originated from anObject, |
|
329 |
evaluate the handleBlock passing it an Exception argument. |
|
330 |
The handler may decide how to react to the signal by sending |
|
331 |
a corresponding message to the exception (see there). |
|
332 |
If the signal is not raised, return the value of evaluating |
|
333 |
aBlock." |
|
334 |
||
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4545
diff
changeset
|
335 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
336 |
<exception: #handle> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
337 |
|
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
338 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
339 |
^ aBlock value "the real logic is in Exception>>doRaise" |
3308 | 340 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
341 |
"Modified: / 26.7.1999 / 00:03:06 / stefan" |
362 | 342 |
! |
343 |
||
2284
8b29d42bb03d
oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents:
2283
diff
changeset
|
344 |
ignoreIn:aBlock |
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
345 |
"evaluate the argument, aBlock. |
21854 | 346 |
Ignore any signal from the receiver during evaluation - i.e. simply continue with the default resume value. |
347 |
This makes only sense for some signals, such as UserInterrupt |
|
21566 | 348 |
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
|
349 |
will often lead to followup-errors." |
159 | 350 |
|
21854 | 351 |
^ self handle:[:ex | ex proceed] do:aBlock. |
159 | 352 |
|
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
353 |
" |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
354 |
SignalSet anySignal ignoreIn:[ |
21566 | 355 |
123 size open |
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
356 |
] |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
357 |
" |
2284
8b29d42bb03d
oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents:
2283
diff
changeset
|
358 |
|
21566 | 359 |
"Created: / 27-01-1997 / 20:32:50 / cg" |
360 |
"Modified (comment): / 24-02-2017 / 11:15:59 / stefan" |
|
21854 | 361 |
"Modified (comment): / 20-06-2017 / 13:35:43 / cg" |
1 | 362 |
! ! |
363 |
||
15064 | 364 |
!SignalSet::SetOfAnySignal class methodsFor:'instance creation'! |
365 |
||
366 |
flushSingleton |
|
367 |
"flushes the cached singleton" |
|
368 |
||
369 |
theOneAndOnlyInstance := nil |
|
370 |
||
371 |
" |
|
372 |
self flushSingleton |
|
373 |
" |
|
374 |
! |
|
375 |
||
376 |
new |
|
377 |
"returns a singleton" |
|
378 |
||
379 |
^ self theOneAndOnlyInstance. |
|
380 |
! |
|
381 |
||
382 |
theOneAndOnlyInstance |
|
383 |
"returns a singleton" |
|
384 |
||
385 |
theOneAndOnlyInstance isNil ifTrue:[ |
|
16562 | 386 |
theOneAndOnlyInstance := self basicNew initialize. |
15064 | 387 |
]. |
388 |
^ theOneAndOnlyInstance. |
|
389 |
! ! |
|
390 |
||
391 |
!SignalSet::SetOfAnySignal methodsFor:'blocked methods'! |
|
392 |
||
393 |
add:anElement |
|
394 |
"do not allow to add anything" |
|
395 |
||
396 |
^ self shouldNotImplement |
|
397 |
! ! |
|
398 |
||
399 |
!SignalSet::SetOfAnySignal methodsFor:'queries'! |
|
400 |
||
23301 | 401 |
accepts:aSignalOrExceptionClass |
15064 | 402 |
"return true, if the receiver accepts the argument, aSignal. |
19445 | 403 |
(i.e. if any of the receiver's elements is aSignal or a parent of it). |
15064 | 404 |
False otherwise. I, the special SetOfAnySignal accepts any (non-query) signal." |
405 |
||
23301 | 406 |
^ aSignalOrExceptionClass isExceptionHandler and:[aSignalOrExceptionClass isQuerySignal not] |
407 |
||
408 |
"Modified (format): / 28-08-2018 / 11:16:55 / Claus Gittinger" |
|
15064 | 409 |
! |
410 |
||
411 |
handles:anException |
|
412 |
"return true, if the receiver handles the argument, anException. |
|
19445 | 413 |
(i.e. if any of the receiver's elements handles anException). |
15064 | 414 |
I, the special SetOfAnySignal handle any (non-query) signal." |
415 |
||
416 |
^ anException isNotification not |
|
417 |
! |
|
418 |
||
419 |
includes:anExceptionHandler |
|
420 |
"return true, if the receiver contains the argument, anExceptionHandler. |
|
421 |
I, the special SetOfAnySignal include any (non-query) ExceptionHandler." |
|
422 |
||
423 |
^ anExceptionHandler isExceptionHandler and:[anExceptionHandler isQuerySignal not] |
|
424 |
! ! |
|
425 |
||
696 | 426 |
!SignalSet class methodsFor:'documentation'! |
427 |
||
428 |
version |
|
19445 | 429 |
^ '$Header$' |
12063 | 430 |
! |
431 |
||
432 |
version_CVS |
|
19445 | 433 |
^ '$Header$' |
696 | 434 |
! ! |
19445 | 435 |