author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sat, 24 Oct 2009 16:48:19 +0100 | |
branch | jv |
changeset 17732 | a1892eeca6c0 |
parent 17711 | 39faaaf888b4 |
child 17734 | 406b1590afe8 |
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 |
" |
|
5836
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
13 |
|
1 | 14 |
IdentitySet subclass:#SignalSet |
1275 | 15 |
instanceVariableNames:'' |
16 |
classVariableNames:'SetOfAnySignal' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Kernel-Exceptions' |
|
1 | 19 |
! |
20 |
||
44 | 21 |
!SignalSet class methodsFor:'documentation'! |
22 |
||
88 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
159 | 26 |
All Rights Reserved |
88 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
44 | 37 |
documentation |
38 |
" |
|
71 | 39 |
SignalSet allows catching of multiple signals. A SignalSet consists of |
95 | 40 |
a number of signals and also implements the #handle:do: and #catch: methods |
41 |
just as signals do. |
|
42 |
However, any signal from the SignalSet will, if signalled, lead into the handler. |
|
159 | 43 |
|
71 | 44 |
There is also a special signalSet, which can be used to catch any |
159 | 45 |
signal in the system - but this should no longer be used, since catching |
46 |
Object>>errorSignal has now the same effect. |
|
1 | 47 |
|
71 | 48 |
For more detail, see comment in Signal and examples in doc/coding. |
95 | 49 |
|
159 | 50 |
Notice: SignalSets are not needed when a group of children of a common signal |
51 |
(such as arithmeticSignal) is to be handled; the parent signal of those will |
|
52 |
also handle all children. |
|
53 |
Use signalSets if totally unrelated signals should be handled by one common |
|
54 |
handler. |
|
1275 | 55 |
|
56 |
||
1292 | 57 |
[author:] |
58 |
Claus Gittinger |
|
59 |
||
1275 | 60 |
[see also:] |
61 |
Exception |
|
62 |
Signal QuerySignal |
|
63 |
Object |
|
44 | 64 |
" |
65 |
! ! |
|
1 | 66 |
|
67 |
!SignalSet class methodsFor:'instance creation'! |
|
68 |
||
69 |
anySignal |
|
159 | 70 |
"return a special signalSet for catching any signal. |
2283 | 71 |
Questionable: |
72 |
you should use 'Object>>errorSignal' for that purpose; |
|
73 |
however, the anySignal-set also catches nonChilds of the ErrorSignal |
|
74 |
(i.e. highly private, strange signals)." |
|
1 | 75 |
|
44 | 76 |
SetOfAnySignal isNil ifTrue:[ |
2283 | 77 |
SetOfAnySignal := self basicNew |
44 | 78 |
]. |
79 |
^ SetOfAnySignal |
|
2283 | 80 |
|
81 |
"Modified: 27.1.1997 / 20:31:08 / cg" |
|
1 | 82 |
! ! |
83 |
||
5836
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
84 |
!SignalSet methodsFor:'adding'! |
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
85 |
|
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
86 |
, anException |
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
87 |
"add anException to the set" |
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
88 |
|
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
89 |
self add:anException |
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
90 |
! ! |
e8265b824b8f
Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents:
4547
diff
changeset
|
91 |
|
622 | 92 |
!SignalSet methodsFor:'queries'! |
93 |
||
8681
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
94 |
accepts:anExceptionHandler |
622 | 95 |
"return true, if the receiver accepts the argument, aSignal. |
96 |
(i.e. if any of the receivers elements is aSignal or a parent of it). |
|
97 |
False otherwise. The special anySet accepts any (non-query) signal." |
|
98 |
||
8681
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
99 |
(self == SetOfAnySignal) ifTrue:[^ anExceptionHandler isQuerySignal not]. |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
100 |
self do:[:eachExceptionHandler | |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
101 |
(eachExceptionHandler==anExceptionHandler |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
102 |
or:[eachExceptionHandler accepts:anExceptionHandler]) ifTrue:[^ true]. |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
103 |
]. |
622 | 104 |
^ false |
105 |
! |
|
106 |
||
8681
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
107 |
exceptionHandlerFor:anException in:aContext |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
108 |
"answer the exceptionHandler for anException from aContext." |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
109 |
|
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
110 |
^ self |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
111 |
! |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
112 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
113 |
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
|
114 |
"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
|
115 |
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
|
116 |
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
|
117 |
|
8699
ed6792665e78
Care for #answer:do: handlers. Must proceed.
Stefan Vogel <sv@exept.de>
parents:
8696
diff
changeset
|
118 |
|selector arg| |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
119 |
|
8699
ed6792665e78
Care for #answer:do: handlers. Must proceed.
Stefan Vogel <sv@exept.de>
parents:
8696
diff
changeset
|
120 |
selector := theContext selector. |
ed6792665e78
Care for #answer:do: handlers. Must proceed.
Stefan Vogel <sv@exept.de>
parents:
8696
diff
changeset
|
121 |
(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
|
122 |
or:[(theContext argAt:2) == originator]) ifTrue:[ |
4512 | 123 |
(self == signal or:[self accepts:signal]) ifTrue:[ |
8699
ed6792665e78
Care for #answer:do: handlers. Must proceed.
Stefan Vogel <sv@exept.de>
parents:
8696
diff
changeset
|
124 |
arg := theContext argAt:1. |
ed6792665e78
Care for #answer:do: handlers. Must proceed.
Stefan Vogel <sv@exept.de>
parents:
8696
diff
changeset
|
125 |
selector == #answer:do: ifTrue:[ |
ed6792665e78
Care for #answer:do: handlers. Must proceed.
Stefan Vogel <sv@exept.de>
parents:
8696
diff
changeset
|
126 |
^ [:ex| ex proceedWith:arg]. |
ed6792665e78
Care for #answer:do: handlers. Must proceed.
Stefan Vogel <sv@exept.de>
parents:
8696
diff
changeset
|
127 |
] ifFalse:[ |
11639
0677f68d6604
changed #handlerForSignal:context:originator:
Stefan Vogel <sv@exept.de>
parents:
9079
diff
changeset
|
128 |
^ arg ? [nil]. |
8699
ed6792665e78
Care for #answer:do: handlers. Must proceed.
Stefan Vogel <sv@exept.de>
parents:
8696
diff
changeset
|
129 |
]. |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
130 |
] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
131 |
]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
132 |
^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
133 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
134 |
"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
|
135 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
136 |
|
4545
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
137 |
handlerProtectedBlock:doBlock inContext:context |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
138 |
"set the handlerProtectedBlock in context" |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
139 |
|
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
140 |
context selector == #handle:do: ifTrue:[ |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
141 |
context argAt:2 put:doBlock. |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
142 |
] ifFalse:[context selector == #handle:from:do: ifTrue:[ |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
143 |
context argAt:3 put:doBlock. |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
144 |
]]. |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
145 |
|
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
146 |
" |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
147 |
SignalSet anySignal |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
148 |
handle:[:ex| ex restartDo:[55]] do:[1 // 0] |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
149 |
" |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
150 |
|
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
151 |
|
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
152 |
"Created: / 25.7.1999 / 23:46:48 / stefan" |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
153 |
! |
9671c4448040
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4512
diff
changeset
|
154 |
|
8681
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
155 |
handles:anException |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
156 |
"return true, if the receiver handles the argument, anException. |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
157 |
(i.e. if any of the receivers elements handles anException)." |
4473
793078981f01
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4465
diff
changeset
|
158 |
|
8681
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
159 |
self == SetOfAnySignal ifTrue:[^ anException isNotification not]. |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
160 |
self do:[:eachExceptionHandler| |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
161 |
(eachExceptionHandler handles:anException) ifTrue:[^ true] |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
162 |
]. |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
163 |
^ false |
4473
793078981f01
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4465
diff
changeset
|
164 |
! |
793078981f01
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4465
diff
changeset
|
165 |
|
622 | 166 |
includes:aSignal |
167 |
"return true, if the receiver contains the argument, aSignal. |
|
168 |
The special any-Set includes every (non-query) signal." |
|
169 |
||
170 |
(self == SetOfAnySignal) ifTrue:[ |
|
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6518
diff
changeset
|
171 |
^ (aSignal isExceptionCreator and:[aSignal isQuerySignal not]) |
622 | 172 |
]. |
173 |
^ super includes:aSignal |
|
6518 | 174 |
! |
175 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6518
diff
changeset
|
176 |
isExceptionHandler |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6518
diff
changeset
|
177 |
"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
|
178 |
especially to the #accepts: and #handles: messages" |
6518 | 179 |
|
180 |
^ true |
|
622 | 181 |
! ! |
182 |
||
1 | 183 |
!SignalSet methodsFor:'save evaluation'! |
184 |
||
8689
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
185 |
answer:someAnswer do:aBlock |
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
186 |
"evaluate the argument, aBlock. |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
187 |
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
|
188 |
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
|
189 |
|
8696
fd361ae49596
#answer:do: must be returnable (see last change)
Stefan Vogel <sv@exept.de>
parents:
8689
diff
changeset
|
190 |
<context: #return> |
8689
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
191 |
<exception: #handle> |
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
192 |
|
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
193 |
"/ thisContext markForHandle. -- same as above pragma |
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
194 |
^ aBlock value. "the real logic is in Exception>>doRaise" |
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
195 |
! |
1fe8db422f77
SignalSet implements #answer:do:
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
196 |
|
622 | 197 |
catch:aBlock |
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
198 |
"evaluate the argument, aBlock. |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
199 |
If any of the signals in the receiver is raised during evaluation, |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
200 |
abort the evaluation and return true; otherwise return false. |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
201 |
With the special anySignal, evaluation can be performed totally save |
9079 | 202 |
from signals - but who (beside radical c++ fans) would do that ?" |
203 |
||
204 |
|raiseOccurred| |
|
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
205 |
|
9079 | 206 |
raiseOccurred := false. |
207 |
self handle:[:ex | raiseOccurred := true. ex return] do:aBlock. |
|
208 |
^ raiseOccurred |
|
622 | 209 |
|
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
210 |
" |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
211 |
SignalSet anySignal catch:[ |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
212 |
(#(1 2 3 4) at:5) / 0.0 |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
213 |
] |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
214 |
" |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
215 |
! |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
216 |
|
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
217 |
deferAfter:aBlock |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
218 |
"evaluate the argument, aBlock. |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
219 |
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
|
220 |
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
|
221 |
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
|
222 |
If the signal is raised multiple times, only the first raises parameter is remembered, |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
223 |
and only a single raise is performed after the blocks evaluation. |
622 | 224 |
|
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
225 |
Deferring makes sense for some signals, such as UserInterrupt or AbortSignal, |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
226 |
which must occasionally be delayed temprarily until a save place is reached |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
227 |
(especially when packages are sent across a communication channel, and you dont want |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
228 |
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
|
229 |
|
6428
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
230 |
|coughtException result| |
622 | 231 |
|
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
232 |
self handle:[:ex | |
6428
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
233 |
coughtException isNil ifTrue:[ |
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
234 |
coughtException := ex. |
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
235 |
]. |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
236 |
ex proceedWith:nil |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
237 |
] do:[ |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
238 |
result := aBlock value. |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
239 |
]. |
6428
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
240 |
coughtException notNil ifTrue:[ |
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
241 |
coughtException suspendedContext:thisContext. |
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
242 |
|
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
243 |
"/ a signal was raised during the execution of aBlock above. |
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
244 |
"/ Raise it now (delayed). |
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
245 |
coughtException raiseSignal |
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
246 |
]. |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
247 |
^ result |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
248 |
|
6428
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
249 |
" |
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
250 |
(UserInterrupt , AbortOperationRequest) deferAfter:[ |
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
251 |
Transcript showCR:'1 - now raising, but will be deferred.'. |
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
252 |
UserInterrupt raiseRequestWith:'hello'. |
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
253 |
Transcript showCR:'2 - after the raise, deferred exception will be handled soon.'. |
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
254 |
]. |
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
255 |
Transcript showCR:'3 - here after the protected block.'. |
8c32b1beb8b4
better impl. of #deferAfter:
Claus Gittinger <cg@exept.de>
parents:
6396
diff
changeset
|
256 |
" |
622 | 257 |
! |
258 |
||
1 | 259 |
handle:handleBlock do:aBlock |
260 |
"evaluate the argument, aBlock. |
|
261 |
If any of the signals in the receiver is raised during evaluation, |
|
262 |
evaluate the handleBlock passing it an Exception argument. |
|
263 |
The handler may decide how to react to the signal by sending |
|
264 |
a corresponding message to the exception (see there). |
|
265 |
If the signal is not raised, return the value of evaluating |
|
266 |
aBlock." |
|
267 |
||
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4545
diff
changeset
|
268 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
269 |
<exception: #handle> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
270 |
|
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
271 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
272 |
^ aBlock value "the real logic is in Exception>>doRaise" |
95 | 273 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
274 |
" |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
275 |
SignalSet anySignal handle:[:ex | |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
276 |
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
|
277 |
ex return |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
278 |
] do:[ |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
279 |
(#(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
|
280 |
] |
4465 | 281 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
282 |
SignalSet anySignal handle:[:ex | |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
283 |
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
|
284 |
self bar. |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
285 |
ex return |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
286 |
] do:[ |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
287 |
(#(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
|
288 |
] |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
289 |
" |
3308 | 290 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
291 |
"Modified: / 26.7.1999 / 00:03:13 / stefan" |
44 | 292 |
! |
293 |
||
362 | 294 |
handle:handleBlock from:anObject do:aBlock |
295 |
"evaluate the argument, aBlock. |
|
296 |
If any of the signals in the receiver is raised during evaluation, |
|
297 |
and the exception originated from anObject, |
|
298 |
evaluate the handleBlock passing it an Exception argument. |
|
299 |
The handler may decide how to react to the signal by sending |
|
300 |
a corresponding message to the exception (see there). |
|
301 |
If the signal is not raised, return the value of evaluating |
|
302 |
aBlock." |
|
303 |
||
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4545
diff
changeset
|
304 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
305 |
<exception: #handle> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
306 |
|
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
307 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
308 |
^ aBlock value "the real logic is in Exception>>doRaise" |
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:06 / stefan" |
362 | 311 |
! |
312 |
||
2284
8b29d42bb03d
oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents:
2283
diff
changeset
|
313 |
ignoreIn:aBlock |
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
314 |
"evaluate the argument, aBlock. |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
315 |
Ignore the any signals from the receiver during evaluation - i.e. simply |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
316 |
continue. This makes only sense for some signals, such as UserInterrupt |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
317 |
or AbortSignals, because continuing after an exception without any cleanup |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
318 |
will often lead to followup-errors." |
159 | 319 |
|
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
320 |
^ self handle:[:ex | ex proceedWith:nil] do:aBlock. |
159 | 321 |
|
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
322 |
" |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
323 |
SignalSet anySignal ignoreIn:[ |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
324 |
123 size open |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
325 |
] |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
326 |
" |
2284
8b29d42bb03d
oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents:
2283
diff
changeset
|
327 |
|
6396
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
328 |
"Created: / 27.1.1997 / 20:32:50 / cg" |
74d5b0b588a6
added deferAfter: - defer exceptions until some later time
Claus Gittinger <cg@exept.de>
parents:
5836
diff
changeset
|
329 |
"Modified: / 4.3.1998 / 16:36:30 / cg" |
1 | 330 |
! ! |
331 |
||
696 | 332 |
!SignalSet class methodsFor:'documentation'! |
333 |
||
334 |
version |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
335 |
^ '$Id: SignalSet.st 10473 2009-10-24 15:48:19Z vranyj1 $' |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
336 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
337 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
338 |
version_CVS |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
339 |
^ '§Header: /cvs/stx/stx/libbasic/SignalSet.st,v 1.45 2009/10/01 07:38:40 cg Exp §' |
696 | 340 |
! ! |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
341 |