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