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