author | Claus Gittinger <cg@exept.de> |
Sun, 02 Nov 1997 20:14:50 +0100 | |
changeset 3089 | 0823aa17ac4d |
parent 3010 | fecaeb40f3dd |
child 3103 | a53892ec3492 |
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 |
Object subclass:#Signal |
|
1249 | 14 |
instanceVariableNames:'mayProceed notifierString nameClass message handlerBlock parent' |
3004
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
15 |
classVariableNames:'NoHandlerSignal GenericSignal' |
1249 | 16 |
poolDictionaries:'' |
17 |
category:'Kernel-Exceptions' |
|
1 | 18 |
! |
19 |
||
2207 | 20 |
!Signal class methodsFor:'documentation'! |
44 | 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 |
" |
|
70 | 38 |
Signal and Exception provide a framework for exception handling. |
44 | 39 |
|
70 | 40 |
A Signal object is usually defined somewhere up in the calling chain |
41 |
and associated with some abnormal event. Many signals are also |
|
42 |
created at startup time and reused. |
|
44 | 43 |
|
70 | 44 |
When the event is raised (by Signal>>raise) the control will be either |
45 |
given to a debugger or - if a handler was defined - to the handler. |
|
46 |
The handler will get a description of what (and where) happened in an |
|
120 | 47 |
Exception object and can decide how to react on the situation (i.e. |
48 |
proceed, return or restart). |
|
70 | 49 |
|
50 |
There is also a companion class called SignalSet, which allows handling |
|
51 |
multiple signals with one handler (for example all arithmetic signals). |
|
52 |
And, finally there is a very special SignalSet which allows catching |
|
53 |
any signal (SignalSet>>anySignal). |
|
54 |
||
171 | 55 |
Since there is no official documentation on signal handling (i.e. none |
56 |
of the books describes it), this Signal implementation has been modeled |
|
57 |
after what some PD programs seem to expect and what alpha/beta testers told |
|
58 |
me it should look like. |
|
59 |
It may not be perfect and undergo minor changes. |
|
44 | 60 |
|
120 | 61 |
special: |
62 |
||
70 | 63 |
In addition to the nested catch & throw mechanism, signals can also be |
120 | 64 |
used when no such handler scope exists. To support this, signals can be |
65 |
assigned a handlerBlock, which gets evaluated with the exception as argument |
|
66 |
in case no handler was found (on the stack). |
|
70 | 67 |
|
171 | 68 |
If no handler was found (i.e. neither a handler context on the stack, nor |
69 |
a static handler block), the NoHandlerSignal will be raised instead, |
|
120 | 70 |
passing it the original exception in its exception-parameter. |
171 | 71 |
This NoHandlerSignal can be handled just like any other signal. |
72 |
(therefore, it is possible to catch any error by catching NoHandlerSignal. |
|
70 | 73 |
|
120 | 74 |
When the NoHandler signal is raised, and neither a handler-context, nor |
75 |
a handler block is defined for it, an emergencyHandler(-block) is evaluated. |
|
76 |
This block is either provided by the current process |
|
77 |
(see Process>>emergencySignalHandler) or as a global default by the Exception |
|
78 |
class (see Exception>>emergencyHandler). |
|
79 |
The default emergencyHandlerBlock (from Exception) will bring up a debugger. |
|
80 |
||
81 |
HandlerBlocks allow a global (if its the EmergencyHandler in Exception) |
|
82 |
or per-process signal handling to be added. Even to code which was never |
|
83 |
planned to handle signals. |
|
70 | 84 |
|
171 | 85 |
See samples in 'doc/coding' and actual raise code in Exception. |
1 | 86 |
|
1275 | 87 |
[Instance variables:] |
70 | 88 |
|
1275 | 89 |
mayProceed <Boolean> hint for the debugger - program may |
90 |
proceed (currently not honored by the |
|
91 |
debugger) |
|
92 |
||
93 |
notifierString <String> error message to be output |
|
70 | 94 |
|
1275 | 95 |
nameClass <Class> for the printOn-implementation; nameClass |
96 |
is the class, to which message (below) |
|
97 |
should be sent to create the receiver. |
|
1 | 98 |
|
1275 | 99 |
message <Symbol> for the printOn-implementation; message |
100 |
is the selector, which should be sent to |
|
101 |
nameClass (above) to create the receiver. |
|
1 | 102 |
|
1275 | 103 |
handlerBlock <Block> if nonNil, a 1-arg block to be |
104 |
evaluated when no handler context is |
|
105 |
found. The block gets the exception |
|
106 |
object as argument. This will play the role |
|
107 |
of an on-stack handler. |
|
108 |
||
109 |
[Class variables:] |
|
70 | 110 |
|
1275 | 111 |
NoHandlerSignal <Signal> signal raised when no handler for a signal |
112 |
was found in raise. |
|
113 |
If this one is not handled either, |
|
114 |
Exceptions emergencyHandler will be evaluated |
|
115 |
instead (or a per-proces handler, if there |
|
116 |
is one). |
|
1292 | 117 |
|
118 |
[author:] |
|
119 |
Claus Gittinger |
|
120 |
||
1275 | 121 |
[see also:] |
122 |
Exception |
|
123 |
SignalSet QuerySignal |
|
124 |
Object |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
125 |
(``Exception handling and signals'': programming/exceptions.html) |
44 | 126 |
" |
127 |
! ! |
|
1 | 128 |
|
2207 | 129 |
!Signal class methodsFor:'initialization'! |
1 | 130 |
|
3004
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
131 |
initGenericSignal |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
132 |
"setup the parent of all signals." |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
133 |
|
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
134 |
GenericSignal isNil ifTrue:[ |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
135 |
GenericSignal := self basicNew notifierString: 'unknown Signal with: '. |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
136 |
GenericSignal nameClass:self message:#genericSignal. |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
137 |
]. |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
138 |
|
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
139 |
"Modified: 8.10.1997 / 11:58:01 / cg" |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
140 |
! |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
141 |
|
159 | 142 |
initialize |
44 | 143 |
"setup the signal used to handle unhandled signals" |
144 |
||
3004
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
145 |
GenericSignal isNil ifTrue:[ |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
146 |
self initGenericSignal. |
3010 | 147 |
]. |
3004
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
148 |
|
3010 | 149 |
NoHandlerSignal isNil ifTrue:[ |
3004
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
150 |
NoHandlerSignal := ErrorSignal newSignalMayProceed:true. |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
151 |
NoHandlerSignal nameClass:self message:#noHandlerSignal. |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
152 |
NoHandlerSignal notifierString:'unhandled exception'. |
61 | 153 |
] |
3004
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
154 |
|
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
155 |
"Modified: 8.10.1997 / 11:48:40 / cg" |
1 | 156 |
! ! |
157 |
||
2207 | 158 |
!Signal class methodsFor:'instance creation'! |
1 | 159 |
|
160 |
new |
|
161 |
"return a new signal" |
|
162 |
||
3008 | 163 |
^ (self basicNew) notifierString:'signal' |
3004
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
164 |
|
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
165 |
" |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
166 |
Signal new |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
167 |
" |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
168 |
|
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
169 |
"Modified: 8.10.1997 / 11:51:39 / cg" |
1 | 170 |
! ! |
171 |
||
2207 | 172 |
!Signal class methodsFor:'Signal constants'! |
1 | 173 |
|
3004
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
174 |
genericSignal |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
175 |
"return the generic signal - thats the parent of all signals |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
176 |
in the system." |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
177 |
|
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
178 |
^ GenericSignal |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
179 |
|
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
180 |
"Created: 8.10.1997 / 11:46:28 / cg" |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
181 |
"Modified: 8.10.1997 / 11:47:08 / cg" |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
182 |
! |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
183 |
|
1 | 184 |
noHandlerSignal |
44 | 185 |
"return the signal used to handle unhandled signals" |
186 |
||
1 | 187 |
^ NoHandlerSignal |
188 |
! ! |
|
189 |
||
622 | 190 |
!Signal methodsFor:'accessing'! |
1 | 191 |
|
622 | 192 |
errorString |
193 |
"return the notifier string" |
|
1 | 194 |
|
622 | 195 |
^ notifierString |
196 |
! |
|
159 | 197 |
|
622 | 198 |
handlerBlock |
199 |
"return the handlerblock - if non-nil, this will be evaluated with the exception |
|
200 |
object as argument, if no #handle:do: context was found on the stack." |
|
201 |
||
202 |
^ handlerBlock |
|
1 | 203 |
! |
204 |
||
622 | 205 |
handlerBlock:aOneArgBlock |
206 |
"set the handlerblock - this will be evaluated with the exception |
|
207 |
object as argument, if no #handle:do: context was found on the stack." |
|
159 | 208 |
|
622 | 209 |
handlerBlock := aOneArgBlock |
210 |
! |
|
159 | 211 |
|
622 | 212 |
mayProceed |
213 |
"return the signals ability to proceed. |
|
214 |
This flag is (currently) not checked by the system; |
|
215 |
be prepared for changes here, to eventually have nonProceedable |
|
216 |
signals refuse to let you continue execution." |
|
1 | 217 |
|
622 | 218 |
^ mayProceed |
1 | 219 |
! |
220 |
||
221 |
mayProceed:aBoolean |
|
44 | 222 |
"set/clear the signals ability to proceed. |
419 | 223 |
This flag is (currently) not checked by the system; |
224 |
be prepared for changes here, to eventually have nonProceedable |
|
225 |
signals refuse to let you continue execution." |
|
1 | 226 |
|
227 |
mayProceed := aBoolean |
|
228 |
! |
|
229 |
||
622 | 230 |
nameClass:aClass message:aSelector |
231 |
"this sets the class & selector of a method which returns |
|
232 |
that signal - this is simply for documentation purposes - |
|
233 |
see Signal>>printOn: implementation. |
|
234 |
(took me a while to find that one out ;-)" |
|
419 | 235 |
|
622 | 236 |
nameClass := aClass. |
237 |
message := aSelector |
|
419 | 238 |
! |
239 |
||
622 | 240 |
notifierString |
241 |
"return the notifier string" |
|
159 | 242 |
|
622 | 243 |
^ notifierString |
244 |
! |
|
245 |
||
246 |
notifierString:aString |
|
247 |
"set the notifier string" |
|
248 |
||
249 |
notifierString := aString |
|
159 | 250 |
! |
251 |
||
252 |
parent |
|
253 |
"return the parent-signal of the receiver" |
|
254 |
||
255 |
^ parent |
|
256 |
! |
|
257 |
||
622 | 258 |
parent:aSignal |
259 |
"set the parent-signal of the receiver." |
|
260 |
||
261 |
parent := aSignal |
|
3004
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
262 |
! |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
263 |
|
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
264 |
parent:aSignal mayProceed:aBoolean |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
265 |
"set the parent-signal and the mayProceed flag of the receiver." |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
266 |
|
3010 | 267 |
parent := aSignal. |
268 |
mayProceed := aBoolean. |
|
3004
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
269 |
|
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
270 |
"Modified: 8.10.1997 / 11:56:11 / cg" |
622 | 271 |
! ! |
272 |
||
273 |
!Signal methodsFor:'copying'! |
|
274 |
||
275 |
deepCopy |
|
276 |
"raise an error - deepCopy is not allowed for signals" |
|
1 | 277 |
|
622 | 278 |
^ self deepCopyError |
279 |
! ! |
|
280 |
||
281 |
!Signal methodsFor:'instance creation'! |
|
1 | 282 |
|
622 | 283 |
newSignal |
284 |
"create a new signal, using the receiver as a prototype and |
|
285 |
setting the parent of the new signal to the receiver." |
|
1 | 286 |
|
3010 | 287 |
^ (self copy) parent:self |
3004
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
288 |
|
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
289 |
"Modified: 8.10.1997 / 11:53:06 / cg" |
70 | 290 |
! |
291 |
||
622 | 292 |
newSignalMayProceed:aBoolean |
293 |
"create a new signal, using the receiver as a prototype and |
|
294 |
setting the parent of the new signal to the receiver." |
|
362 | 295 |
|
3010 | 296 |
^ (self copy) parent:self mayProceed:aBoolean |
70 | 297 |
|
3004
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
298 |
"Modified: 8.10.1997 / 11:57:13 / cg" |
1 | 299 |
! ! |
300 |
||
159 | 301 |
!Signal methodsFor:'printing'! |
302 |
||
303 |
printOn:aStream |
|
304 |
"append a printed representation of the receiver on aStream" |
|
305 |
||
306 |
nameClass notNil ifTrue:[ |
|
307 |
aStream nextPutAll:nameClass name. |
|
308 |
aStream space. |
|
309 |
aStream nextPutAll:message. |
|
310 |
^ self |
|
311 |
]. |
|
312 |
^ super printOn:aStream |
|
313 |
! ! |
|
314 |
||
622 | 315 |
!Signal methodsFor:'private'! |
316 |
||
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
317 |
errorStringFor:errorString with:aParameter |
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
318 |
"used when raising with a given error string and/or parameter; |
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
319 |
if the errorString starts with a space, it is appended to the receivers |
622 | 320 |
notifier string; if it ends with a space, it is prepended. |
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
321 |
Otherwise, the errorString is returned. |
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
322 |
If no errorString is given, use the signals default notifierString." |
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
323 |
|
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2207
diff
changeset
|
324 |
|t| |
622 | 325 |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
326 |
errorString isNil ifTrue:[ |
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
327 |
t := notifierString |
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
328 |
] ifFalse:[ |
2497 | 329 |
t := errorString. |
330 |
(errorString endsWith:Character space) ifTrue:[ |
|
331 |
t := errorString , notifierString |
|
332 |
] ifFalse:[ |
|
333 |
(errorString startsWith:Character space) ifTrue:[ |
|
334 |
t := notifierString , errorString |
|
335 |
] |
|
336 |
]. |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
337 |
]. |
2497 | 338 |
^ t. |
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
339 |
|
2497 | 340 |
"/ aParameter isNil ifTrue:[ |
341 |
"/ ^ t |
|
342 |
"/ ]. |
|
343 |
"/ |
|
344 |
"/ (t startsWith:' ') ifTrue:[ |
|
345 |
"/ ^ aParameter printString , t |
|
346 |
"/ ]. |
|
347 |
"/ (t endsWith:' ') ifTrue:[ |
|
348 |
"/ ^ t , aParameter printString |
|
349 |
"/ ]. |
|
350 |
"/ ^ t |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
351 |
|
2497 | 352 |
"Modified: 25.3.1997 / 12:12:37 / cg" |
622 | 353 |
! ! |
354 |
||
355 |
!Signal methodsFor:'queries'! |
|
356 |
||
357 |
accepts:aSignal |
|
358 |
"return true, if the receiver accepts the argument, aSignal. |
|
359 |
(i.e. the receiver is aSignal or a parent of it). False otherwise." |
|
360 |
||
361 |
|s| |
|
362 |
||
363 |
aSignal isQuerySignal ifTrue:[^ false]. |
|
364 |
||
365 |
s := aSignal. |
|
366 |
[s notNil] whileTrue:[ |
|
367 |
self == s ifTrue:[^ true]. |
|
368 |
s := s parent |
|
369 |
]. |
|
370 |
^ false |
|
371 |
! |
|
372 |
||
373 |
inheritsFrom:anotherSignal |
|
374 |
"return true, if the receiver is a child of anotherSignal |
|
375 |
(i.e. if handling anotherSignal also handles the receiver) |
|
376 |
This is almost the same as accepts, but returns false, if |
|
377 |
the receiver is identical to anotherSignal." |
|
378 |
||
379 |
self == anotherSignal ifTrue:[^ false]. |
|
380 |
^ anotherSignal accepts:self |
|
381 |
! |
|
382 |
||
383 |
isHandled |
|
384 |
"return true, if there is a handler for the receiver signal. |
|
385 |
Raising an unhandled signal will usually lead into the debugger, |
|
2689 | 386 |
but can be caught globally by setting Exceptions EmergencyHandler." |
622 | 387 |
|
388 |
^ self isHandledIn:(thisContext sender). |
|
389 |
! |
|
390 |
||
391 |
isHandledIn:aContext |
|
392 |
"return true, if there is a handler for the receiver signal in the |
|
393 |
contextChain starting with aContext." |
|
394 |
||
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2207
diff
changeset
|
395 |
|con| |
622 | 396 |
|
397 |
con := aContext. |
|
398 |
[con notNil] whileTrue:[ |
|
2893 | 399 |
con := con findNextContextWithSelector:#'handle:do:' or:#'handle:from:do:' or:nil. |
2207 | 400 |
con notNil ifTrue:[ |
401 |
" |
|
402 |
is this is a #handle:do: or a #handle:from:do: context |
|
403 |
with self in it ? |
|
404 |
" |
|
405 |
(con receiver accepts:self) ifTrue:[ |
|
406 |
"found a handler context" |
|
622 | 407 |
|
2207 | 408 |
^ true |
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2207
diff
changeset
|
409 |
] |
2207 | 410 |
] |
622 | 411 |
]. |
412 |
^ false |
|
2207 | 413 |
|
414 |
"Modified: 20.1.1997 / 12:45:01 / cg" |
|
622 | 415 |
! |
416 |
||
417 |
isQuerySignal |
|
1249 | 418 |
"return true, if this is a querySignal - always return false here" |
419 |
||
622 | 420 |
^ false |
1249 | 421 |
|
422 |
"Modified: 22.4.1996 / 13:45:06 / cg" |
|
622 | 423 |
! |
424 |
||
425 |
isSignal |
|
426 |
"return true, if the receiver is some kind of signal; |
|
427 |
true returned here - the method is redefined from Object." |
|
428 |
||
429 |
^ true |
|
430 |
! ! |
|
431 |
||
432 |
!Signal methodsFor:'raising'! |
|
433 |
||
434 |
raise |
|
1326 | 435 |
"raise a signal nonproceedable |
436 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
437 |
non proceedable exceptions. |
|
622 | 438 |
The signals notifierString is used as errorString." |
439 |
||
440 |
^ (Exception |
|
1326 | 441 |
signal:self |
442 |
parameter:nil |
|
443 |
errorString:notifierString |
|
444 |
suspendedContext:thisContext sender) raise. |
|
445 |
||
446 |
"Modified: 2.5.1996 / 16:36:23 / cg" |
|
622 | 447 |
! |
448 |
||
449 |
raiseErrorString:aString |
|
1326 | 450 |
"raise a signal nonproceedable. |
451 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
452 |
non proceedable exceptions. |
|
622 | 453 |
The argument is used as errorString." |
454 |
||
455 |
^ (Exception |
|
1326 | 456 |
signal:self |
457 |
parameter:nil |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
458 |
errorString:(self errorStringFor:aString with:nil) |
1326 | 459 |
suspendedContext:thisContext sender) raise. |
460 |
||
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
461 |
"Modified: 9.5.1996 / 15:17:59 / cg" |
622 | 462 |
! |
463 |
||
1610 | 464 |
raiseErrorString:aString in:aContext |
465 |
"raise a signal nonproceedable. |
|
466 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
467 |
non proceedable exceptions. |
|
468 |
The argument is used as errorString. |
|
469 |
The additional context is passed as the context responsible for the raise, |
|
470 |
allowing a raise to mimicri the exception happened somewhere else." |
|
471 |
||
472 |
^ (Exception |
|
473 |
signal:self |
|
474 |
parameter:nil |
|
475 |
errorString:(self errorStringFor:aString with:nil) |
|
476 |
suspendedContext:aContext) raise. |
|
477 |
||
478 |
"Created: 26.7.1996 / 16:42:32 / cg" |
|
479 |
"Modified: 26.7.1996 / 16:42:47 / cg" |
|
480 |
! |
|
481 |
||
622 | 482 |
raiseFrom:something |
1326 | 483 |
"raise a signal nonproceedable. |
484 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
485 |
non proceedable exceptions. |
|
622 | 486 |
The argument, something is passed both as parameter and originator. |
487 |
XXX: I am not certain, if this is the correct behavior (seen in remoteInvocation-goodie)" |
|
488 |
||
489 |
^ (Exception |
|
1326 | 490 |
signal:self |
491 |
parameter:something |
|
492 |
errorString:notifierString |
|
493 |
suspendedContext:thisContext sender |
|
494 |
originator:something) raise. |
|
495 |
||
496 |
"Modified: 2.5.1996 / 16:36:38 / cg" |
|
622 | 497 |
! |
498 |
||
499 |
raiseIn:aContext |
|
1326 | 500 |
"raise a signal nonproceedable. |
501 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
502 |
non proceedable exceptions. |
|
622 | 503 |
The signals notifierString is used as errorString. |
504 |
The additional context is passed as the context responsible for the raise, |
|
505 |
allowing a raise to mimicri the exception happened somewhere else." |
|
506 |
||
507 |
^ (Exception |
|
1326 | 508 |
signal:self |
509 |
parameter:nil |
|
510 |
errorString:notifierString |
|
511 |
suspendedContext:aContext) raise. |
|
512 |
||
513 |
"Modified: 2.5.1996 / 16:36:44 / cg" |
|
622 | 514 |
! |
515 |
||
516 |
raiseRequest |
|
1326 | 517 |
"raise a signal proceedable. |
622 | 518 |
The signals notifierString is used as errorString." |
519 |
||
520 |
^ (Exception |
|
1326 | 521 |
signal:self |
522 |
parameter:nil |
|
523 |
errorString:notifierString |
|
524 |
suspendedContext:thisContext sender) raiseRequest. |
|
525 |
||
526 |
"Modified: 2.5.1996 / 16:36:52 / cg" |
|
622 | 527 |
! |
528 |
||
529 |
raiseRequestWith:aParameter |
|
1326 | 530 |
"raise a signal proceedable. |
622 | 531 |
The signals notifierString is used as errorString." |
532 |
||
533 |
^ (Exception |
|
1326 | 534 |
signal:self |
535 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
536 |
errorString:(self errorStringFor:nil with:aParameter) |
1326 | 537 |
suspendedContext:thisContext sender) raiseRequest. |
538 |
||
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
539 |
"Modified: 9.5.1996 / 15:13:20 / cg" |
622 | 540 |
! |
541 |
||
542 |
raiseRequestWith:aParameter errorString:aString |
|
1326 | 543 |
"raise a signal proceedable. |
622 | 544 |
The argument, aString is used as errorString." |
545 |
||
546 |
^ (Exception |
|
1326 | 547 |
signal:self |
548 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
549 |
errorString:(self errorStringFor:aString with:aParameter) |
1326 | 550 |
suspendedContext:thisContext sender) raiseRequest |
551 |
||
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
552 |
"Modified: 9.5.1996 / 15:13:35 / cg" |
622 | 553 |
! |
554 |
||
555 |
raiseRequestWith:aParameter errorString:aString in:aContext |
|
1326 | 556 |
"raise a signal proceedable. |
622 | 557 |
The argument, aString is used as errorString. |
1608 | 558 |
The additional context is passed as the context responsible for the raise, |
559 |
allowing a raise to mimicri the exception happened somewhere else." |
|
622 | 560 |
|
561 |
^ (Exception |
|
1326 | 562 |
signal:self |
563 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
564 |
errorString:(self errorStringFor:aString with:aParameter) |
1326 | 565 |
suspendedContext:aContext) raiseRequest |
566 |
||
1608 | 567 |
"Modified: 26.7.1996 / 16:29:27 / cg" |
622 | 568 |
! |
569 |
||
570 |
raiseRequestWith:aParameter in:aContext |
|
1326 | 571 |
"raise a signal proceedable. |
622 | 572 |
The signals notifierString is used as errorString. |
1608 | 573 |
The additional context is passed as the context responsible for the raise, |
574 |
allowing a raise to mimicri the exception happened somewhere else." |
|
622 | 575 |
|
576 |
^ (Exception |
|
1326 | 577 |
signal:self |
578 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
579 |
errorString:(self errorStringFor:nil with:aParameter) |
1326 | 580 |
suspendedContext:aContext) raiseRequest. |
581 |
||
1608 | 582 |
"Modified: 26.7.1996 / 16:29:33 / cg" |
622 | 583 |
! |
584 |
||
585 |
raiseWith:aParameter |
|
1326 | 586 |
"raise a signal nonproceedable. |
587 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
588 |
non proceedable exceptions. |
|
622 | 589 |
The argument, aParameter is passed as parameter. |
590 |
XXX: I am not certain, if this is the correct behavior (seen in remoteInvocation-goodie)" |
|
591 |
||
592 |
^ (Exception |
|
1326 | 593 |
signal:self |
594 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
595 |
errorString:(self errorStringFor:nil with:aParameter) |
1326 | 596 |
suspendedContext:thisContext sender) raise. |
597 |
||
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
598 |
"Modified: 9.5.1996 / 15:14:24 / cg" |
622 | 599 |
! |
600 |
||
601 |
raiseWith:aParameter errorString:aString |
|
1326 | 602 |
"raise a signal nonproceedable |
603 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
604 |
non proceedable exceptions. |
|
622 | 605 |
The argument, aString is used as errorString, aParameter is passed |
606 |
as exception parameter." |
|
607 |
||
608 |
^ (Exception |
|
1326 | 609 |
signal:self |
610 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
611 |
errorString:(self errorStringFor:aString with:aParameter) |
1326 | 612 |
suspendedContext:thisContext sender) raise. |
613 |
||
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
614 |
"Modified: 9.5.1996 / 15:14:32 / cg" |
1326 | 615 |
! |
616 |
||
617 |
raiseWith:aParameter errorString:aString in:aContext |
|
618 |
"raise a signal nonproceedable |
|
619 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
620 |
non proceedable exceptions. |
|
621 |
The argument, aString is used as errorString, aParameter is passed |
|
1608 | 622 |
as exception parameter. |
623 |
The additional context is passed as the context responsible for the raise, |
|
624 |
allowing a raise to mimicri the exception happened somewhere else." |
|
625 |
||
1326 | 626 |
|
627 |
^ (Exception |
|
628 |
signal:self |
|
629 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
630 |
errorString:(self errorStringFor:aString with:aParameter) |
1326 | 631 |
suspendedContext:aContext) raise. |
632 |
||
633 |
"Created: 2.5.1996 / 16:37:25 / cg" |
|
1608 | 634 |
"Modified: 26.7.1996 / 16:29:42 / cg" |
622 | 635 |
! ! |
636 |
||
1 | 637 |
!Signal methodsFor:'save evaluation'! |
638 |
||
622 | 639 |
catch:aBlock |
640 |
"evaluate the argument, aBlock. |
|
641 |
If the receiver-signal is raised during evaluation, abort |
|
642 |
the evaluation and return true; otherwise return false. |
|
643 |
This is the catch & throw mechanism found in other languages, |
|
644 |
where the returned value indicates if an exception occured." |
|
645 |
||
646 |
|raiseOccurred| |
|
647 |
||
648 |
raiseOccurred := false. |
|
649 |
self handle:[:ex | raiseOccurred := true. ex return] do:aBlock. |
|
650 |
^ raiseOccurred |
|
651 |
||
652 |
" |
|
653 |
Object messageNotUnderstoodSignal catch:[ |
|
654 |
123 size open |
|
655 |
] |
|
656 |
" |
|
657 |
! |
|
658 |
||
1 | 659 |
handle:handleBlock do:aBlock |
660 |
"evaluate the argument, aBlock. |
|
661 |
If the receiver-signal is raised during evaluation, |
|
662 |
evaluate the handleBlock passing it an Exception argument. |
|
663 |
The handler may decide how to react to the signal by sending |
|
664 |
a corresponding message to the exception (see there). |
|
665 |
If the signal is not raised, return the value of evaluating |
|
666 |
aBlock." |
|
667 |
||
668 |
^ aBlock value "the real logic is in raise/Exception" |
|
95 | 669 |
|
670 |
" |
|
671 |
Object messageNotUnderstoodSignal handle:[:ex | |
|
159 | 672 |
'oops' printNL. |
673 |
ex return |
|
95 | 674 |
] do:[ |
159 | 675 |
123 size open |
95 | 676 |
] |
677 |
" |
|
120 | 678 |
|
95 | 679 |
" |
680 |
|num| |
|
681 |
||
682 |
num := 0. |
|
683 |
Number divisionByZeroSignal handle:[:ex | |
|
159 | 684 |
'oops' printNL. |
685 |
ex return |
|
95 | 686 |
] do:[ |
159 | 687 |
123 / num |
95 | 688 |
] |
689 |
" |
|
44 | 690 |
! |
691 |
||
362 | 692 |
handle:handleBlock from:anObject do:aBlock |
693 |
"evaluate the argument, aBlock. |
|
694 |
If the receiver-signal is raised during evaluation, |
|
695 |
and the exception originated from anObject, |
|
696 |
evaluate the handleBlock passing it an Exception argument. |
|
697 |
The handler may decide how to react to the signal by sending |
|
698 |
a corresponding message to the exception (see there). |
|
699 |
If the signal is not raised, return the value of evaluating |
|
700 |
aBlock." |
|
701 |
||
702 |
^ aBlock value "the real logic is in raise/Exception" |
|
703 |
||
704 |
" |
|
2689 | 705 |
the first open will be caught; the second not: |
362 | 706 |
|
707 |
|o1 o2| |
|
708 |
||
709 |
o1 := 123. |
|
710 |
o2 := nil. |
|
711 |
Object messageNotUnderstoodSignal |
|
712 |
handle: |
|
713 |
[:ex | |
|
714 |
'oops' printNL. |
|
715 |
ex proceed |
|
716 |
] |
|
717 |
from:o1 |
|
718 |
do: |
|
719 |
[ |
|
720 |
o1 open. |
|
721 |
o2 open |
|
722 |
] |
|
723 |
" |
|
724 |
! |
|
725 |
||
419 | 726 |
ignoreIn:aBlock |
159 | 727 |
"evaluate the argument, aBlock. |
728 |
Ignore the receiver-signal during evaluation - i.e. simply |
|
419 | 729 |
continue. |
730 |
This makes only sense for some signals, such as UserInterrupt |
|
731 |
or AbortSignal, because continuing after an exception without any cleanup |
|
732 |
often leads to followup-errors." |
|
159 | 733 |
|
734 |
^ self handle:[:ex | ex proceed] do:aBlock. |
|
735 |
||
736 |
" |
|
419 | 737 |
Object messageNotUnderstoodSignal ignoreIn:[ |
159 | 738 |
123 size open |
61 | 739 |
] |
740 |
" |
|
1 | 741 |
! ! |
742 |
||
2207 | 743 |
!Signal class methodsFor:'documentation'! |
1249 | 744 |
|
745 |
version |
|
3010 | 746 |
^ '$Header: /cvs/stx/stx/libbasic/Signal.st,v 1.46 1997-10-08 13:56:49 cg Exp $' |
1249 | 747 |
! ! |
622 | 748 |
Signal initialize! |