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