author | Stefan Vogel <sv@exept.de> |
Wed, 28 Jul 1999 09:53:29 +0200 | |
changeset 4464 | cec93c942c14 |
parent 3311 | 2f7f489ebff8 |
child 4465 | 8dfbc6d6ccf3 |
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 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
13 |
'From Smalltalk/X, Version:3.5.3 on 26-jul-1999 at 00:03:17' ! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
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 |
||
622 | 85 |
!SignalSet methodsFor:'queries'! |
86 |
||
87 |
accepts:aSignal |
|
88 |
"return true, if the receiver accepts the argument, aSignal. |
|
89 |
(i.e. if any of the receivers elements is aSignal or a parent of it). |
|
90 |
False otherwise. The special anySet accepts any (non-query) signal." |
|
91 |
||
92 |
(self == SetOfAnySignal) ifTrue:[^ aSignal isQuerySignal not]. |
|
93 |
self do:[:sig | (sig accepts:aSignal) ifTrue:[^ true]]. |
|
94 |
^ false |
|
95 |
! |
|
96 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
97 |
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
|
98 |
"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
|
99 |
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
|
100 |
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
|
101 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
102 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
103 |
(theContext selector ~~ #'handle:from:do:' |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
104 |
or:[(theContext argAt:2) == originator]) ifTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
105 |
(self accepts:signal) ifTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
106 |
^ theContext argAt:1 |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
107 |
] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
108 |
]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
109 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
110 |
^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
111 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
112 |
"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
|
113 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
114 |
|
622 | 115 |
includes:aSignal |
116 |
"return true, if the receiver contains the argument, aSignal. |
|
117 |
The special any-Set includes every (non-query) signal." |
|
118 |
||
119 |
(self == SetOfAnySignal) ifTrue:[ |
|
120 |
^ (aSignal isSignal and:[aSignal isQuerySignal not]) |
|
121 |
]. |
|
122 |
^ super includes:aSignal |
|
123 |
! ! |
|
124 |
||
1 | 125 |
!SignalSet methodsFor:'save evaluation'! |
126 |
||
622 | 127 |
catch:aBlock |
128 |
"evaluate the argument, aBlock. |
|
129 |
If any of the signals in the receiver is raised during evaluation, |
|
130 |
abort the evaluation and return true; otherwise return false. |
|
131 |
With the special anySignal, evaluation can be performed totally save |
|
132 |
from signals |
|
133 |
- but who (beside radical c++ fans) would do that ?" |
|
134 |
||
135 |
|raiseOccurred| |
|
136 |
||
137 |
raiseOccurred := false. |
|
138 |
self handle:[:ex | raiseOccurred := true. ex return] do:aBlock. |
|
139 |
^ raiseOccurred |
|
140 |
||
141 |
" |
|
142 |
SignalSet anySignal catch:[ |
|
143 |
(#(1 2 3 4) at:5) / 0.0 |
|
144 |
] |
|
145 |
" |
|
146 |
! |
|
147 |
||
1 | 148 |
handle:handleBlock do:aBlock |
149 |
"evaluate the argument, aBlock. |
|
150 |
If any of the signals in the receiver is raised during evaluation, |
|
151 |
evaluate the handleBlock passing it an Exception argument. |
|
152 |
The handler may decide how to react to the signal by sending |
|
153 |
a corresponding message to the exception (see there). |
|
154 |
If the signal is not raised, return the value of evaluating |
|
155 |
aBlock." |
|
156 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
157 |
thisContext markForHandle. |
3308 | 158 |
^ aBlock value "the real logic is in Exception>>doRaise" |
95 | 159 |
|
160 |
" |
|
161 |
SignalSet anySignal handle:[:ex | |
|
3308 | 162 |
ex errorString print. ' occured in: ' print. ex suspendedContext printNL. |
163 |
ex return |
|
95 | 164 |
] do:[ |
3308 | 165 |
(#(1 2 3 4) at:5) / 0.0 |
95 | 166 |
] |
167 |
" |
|
3308 | 168 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
169 |
"Modified: / 26.7.1999 / 00:03:13 / stefan" |
44 | 170 |
! |
171 |
||
362 | 172 |
handle:handleBlock from:anObject do:aBlock |
173 |
"evaluate the argument, aBlock. |
|
174 |
If any of the signals in the receiver is raised during evaluation, |
|
175 |
and the exception originated from anObject, |
|
176 |
evaluate the handleBlock passing it an Exception argument. |
|
177 |
The handler may decide how to react to the signal by sending |
|
178 |
a corresponding message to the exception (see there). |
|
179 |
If the signal is not raised, return the value of evaluating |
|
180 |
aBlock." |
|
181 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
182 |
thisContext markForHandle. |
3308 | 183 |
^ aBlock value "the real logic is in Exception>>doRaise" |
184 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
185 |
"Modified: / 26.7.1999 / 00:03:06 / stefan" |
362 | 186 |
! |
187 |
||
2284
8b29d42bb03d
oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents:
2283
diff
changeset
|
188 |
ignoreIn:aBlock |
159 | 189 |
"evaluate the argument, aBlock. |
2284
8b29d42bb03d
oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents:
2283
diff
changeset
|
190 |
Ignore the any signals from the receiver during evaluation - i.e. simply |
159 | 191 |
continue. This makes only sense for some signals, such as UserInterrupt |
192 |
or AbortSignals, because continuing after an exception without any cleanup |
|
193 |
will often lead to followup-errors." |
|
194 |
||
195 |
^ self handle:[:ex | ex proceed] do:aBlock. |
|
196 |
||
197 |
" |
|
3311 | 198 |
SignalSet anySignal ignoreIn:[ |
2284
8b29d42bb03d
oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents:
2283
diff
changeset
|
199 |
123 size open |
95 | 200 |
] |
201 |
" |
|
2284
8b29d42bb03d
oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents:
2283
diff
changeset
|
202 |
|
3311 | 203 |
"Created: / 27.1.1997 / 20:32:50 / cg" |
204 |
"Modified: / 4.3.1998 / 16:36:30 / cg" |
|
1 | 205 |
! ! |
206 |
||
696 | 207 |
!SignalSet class methodsFor:'documentation'! |
208 |
||
209 |
version |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
3311
diff
changeset
|
210 |
^ '$Header: /cvs/stx/stx/libbasic/SignalSet.st,v 1.25 1999-07-28 07:53:29 stefan Exp $' |
696 | 211 |
! ! |