author | Stefan Vogel <sv@exept.de> |
Mon, 02 Mar 1998 15:23:13 +0100 | |
changeset 3308 | a6848d4b875d |
parent 2284 | 8b29d42bb03d |
child 3311 | 2f7f489ebff8 |
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 |
||
13 |
IdentitySet subclass:#SignalSet |
|
1275 | 14 |
instanceVariableNames:'' |
15 |
classVariableNames:'SetOfAnySignal' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Kernel-Exceptions' |
|
1 | 18 |
! |
19 |
||
44 | 20 |
!SignalSet class methodsFor:'documentation'! |
21 |
||
88 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
159 | 25 |
All Rights Reserved |
88 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
44 | 36 |
documentation |
37 |
" |
|
71 | 38 |
SignalSet allows catching of multiple signals. A SignalSet consists of |
95 | 39 |
a number of signals and also implements the #handle:do: and #catch: methods |
40 |
just as signals do. |
|
41 |
However, any signal from the SignalSet will, if signalled, lead into the handler. |
|
159 | 42 |
|
71 | 43 |
There is also a special signalSet, which can be used to catch any |
159 | 44 |
signal in the system - but this should no longer be used, since catching |
45 |
Object>>errorSignal has now the same effect. |
|
1 | 46 |
|
71 | 47 |
For more detail, see comment in Signal and examples in doc/coding. |
95 | 48 |
|
159 | 49 |
Notice: SignalSets are not needed when a group of children of a common signal |
50 |
(such as arithmeticSignal) is to be handled; the parent signal of those will |
|
51 |
also handle all children. |
|
52 |
Use signalSets if totally unrelated signals should be handled by one common |
|
53 |
handler. |
|
1275 | 54 |
|
55 |
||
1292 | 56 |
[author:] |
57 |
Claus Gittinger |
|
58 |
||
1275 | 59 |
[see also:] |
60 |
Exception |
|
61 |
Signal QuerySignal |
|
62 |
Object |
|
44 | 63 |
" |
64 |
! ! |
|
1 | 65 |
|
66 |
!SignalSet class methodsFor:'instance creation'! |
|
67 |
||
68 |
anySignal |
|
159 | 69 |
"return a special signalSet for catching any signal. |
2283 | 70 |
Questionable: |
71 |
you should use 'Object>>errorSignal' for that purpose; |
|
72 |
however, the anySignal-set also catches nonChilds of the ErrorSignal |
|
73 |
(i.e. highly private, strange signals)." |
|
1 | 74 |
|
44 | 75 |
SetOfAnySignal isNil ifTrue:[ |
2283 | 76 |
SetOfAnySignal := self basicNew |
44 | 77 |
]. |
78 |
^ SetOfAnySignal |
|
2283 | 79 |
|
80 |
"Modified: 27.1.1997 / 20:31:08 / cg" |
|
1 | 81 |
! ! |
82 |
||
622 | 83 |
!SignalSet methodsFor:'queries'! |
84 |
||
85 |
accepts:aSignal |
|
86 |
"return true, if the receiver accepts the argument, aSignal. |
|
87 |
(i.e. if any of the receivers elements is aSignal or a parent of it). |
|
88 |
False otherwise. The special anySet accepts any (non-query) signal." |
|
89 |
||
90 |
(self == SetOfAnySignal) ifTrue:[^ aSignal isQuerySignal not]. |
|
91 |
self do:[:sig | (sig accepts:aSignal) ifTrue:[^ true]]. |
|
92 |
^ false |
|
93 |
! |
|
94 |
||
95 |
includes:aSignal |
|
96 |
"return true, if the receiver contains the argument, aSignal. |
|
97 |
The special any-Set includes every (non-query) signal." |
|
98 |
||
99 |
(self == SetOfAnySignal) ifTrue:[ |
|
100 |
^ (aSignal isSignal and:[aSignal isQuerySignal not]) |
|
101 |
]. |
|
102 |
^ super includes:aSignal |
|
103 |
! ! |
|
104 |
||
1 | 105 |
!SignalSet methodsFor:'save evaluation'! |
106 |
||
622 | 107 |
catch:aBlock |
108 |
"evaluate the argument, aBlock. |
|
109 |
If any of the signals in the receiver is raised during evaluation, |
|
110 |
abort the evaluation and return true; otherwise return false. |
|
111 |
With the special anySignal, evaluation can be performed totally save |
|
112 |
from signals |
|
113 |
- but who (beside radical c++ fans) would do that ?" |
|
114 |
||
115 |
|raiseOccurred| |
|
116 |
||
117 |
raiseOccurred := false. |
|
118 |
self handle:[:ex | raiseOccurred := true. ex return] do:aBlock. |
|
119 |
^ raiseOccurred |
|
120 |
||
121 |
" |
|
122 |
SignalSet anySignal catch:[ |
|
123 |
(#(1 2 3 4) at:5) / 0.0 |
|
124 |
] |
|
125 |
" |
|
126 |
! |
|
127 |
||
1 | 128 |
handle:handleBlock do:aBlock |
129 |
"evaluate the argument, aBlock. |
|
130 |
If any of the signals in the receiver is raised during evaluation, |
|
131 |
evaluate the handleBlock passing it an Exception argument. |
|
132 |
The handler may decide how to react to the signal by sending |
|
133 |
a corresponding message to the exception (see there). |
|
134 |
If the signal is not raised, return the value of evaluating |
|
135 |
aBlock." |
|
136 |
||
3308 | 137 |
^ aBlock value "the real logic is in Exception>>doRaise" |
95 | 138 |
|
139 |
" |
|
140 |
SignalSet anySignal handle:[:ex | |
|
3308 | 141 |
ex errorString print. ' occured in: ' print. ex suspendedContext printNL. |
142 |
ex return |
|
95 | 143 |
] do:[ |
3308 | 144 |
(#(1 2 3 4) at:5) / 0.0 |
95 | 145 |
] |
146 |
" |
|
3308 | 147 |
|
148 |
"Modified: / 2.3.1998 / 14:28:47 / stefan" |
|
44 | 149 |
! |
150 |
||
362 | 151 |
handle:handleBlock from:anObject do:aBlock |
152 |
"evaluate the argument, aBlock. |
|
153 |
If any of the signals in the receiver is raised during evaluation, |
|
154 |
and the exception originated from anObject, |
|
155 |
evaluate the handleBlock passing it an Exception argument. |
|
156 |
The handler may decide how to react to the signal by sending |
|
157 |
a corresponding message to the exception (see there). |
|
158 |
If the signal is not raised, return the value of evaluating |
|
159 |
aBlock." |
|
160 |
||
3308 | 161 |
^ aBlock value "the real logic is in Exception>>doRaise" |
162 |
||
163 |
"Modified: / 2.3.1998 / 14:28:58 / stefan" |
|
362 | 164 |
! |
165 |
||
2284
8b29d42bb03d
oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents:
2283
diff
changeset
|
166 |
ignoreIn:aBlock |
159 | 167 |
"evaluate the argument, aBlock. |
2284
8b29d42bb03d
oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents:
2283
diff
changeset
|
168 |
Ignore the any signals from the receiver during evaluation - i.e. simply |
159 | 169 |
continue. This makes only sense for some signals, such as UserInterrupt |
170 |
or AbortSignals, because continuing after an exception without any cleanup |
|
171 |
will often lead to followup-errors." |
|
172 |
||
173 |
^ self handle:[:ex | ex proceed] do:aBlock. |
|
174 |
||
175 |
" |
|
176 |
SignalSet anySignal ignore:[ |
|
2284
8b29d42bb03d
oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents:
2283
diff
changeset
|
177 |
123 size open |
95 | 178 |
] |
179 |
" |
|
2284
8b29d42bb03d
oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents:
2283
diff
changeset
|
180 |
|
8b29d42bb03d
oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents:
2283
diff
changeset
|
181 |
"Created: 27.1.1997 / 20:32:50 / cg" |
1 | 182 |
! ! |
183 |
||
696 | 184 |
!SignalSet class methodsFor:'documentation'! |
185 |
||
186 |
version |
|
3308 | 187 |
^ '$Header: /cvs/stx/stx/libbasic/SignalSet.st,v 1.23 1998-03-02 14:23:13 stefan Exp $' |
696 | 188 |
! ! |