author | Claus Gittinger <cg@exept.de> |
Sat, 22 Mar 1997 16:19:44 +0100 | |
changeset 2484 | 05bd2cc43192 |
parent 2291 | af7652b82404 |
child 2497 | 5aaa953d3e40 |
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' |
15 |
classVariableNames:'NoHandlerSignal' |
|
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 |
|
159 | 131 |
initialize |
44 | 132 |
"setup the signal used to handle unhandled signals" |
133 |
||
61 | 134 |
NoHandlerSignal isNil ifTrue:[ |
302 | 135 |
NoHandlerSignal := ErrorSignal newSignalMayProceed:true. |
159 | 136 |
NoHandlerSignal nameClass:self message:#noHandlerSignal. |
137 |
NoHandlerSignal notifierString:'unhandled exception'. |
|
61 | 138 |
] |
1 | 139 |
! ! |
140 |
||
2207 | 141 |
!Signal class methodsFor:'instance creation'! |
1 | 142 |
|
143 |
new |
|
144 |
"return a new signal" |
|
145 |
||
419 | 146 |
^ (self basicNew) notifierString:'signal' |
1 | 147 |
! ! |
148 |
||
2207 | 149 |
!Signal class methodsFor:'Signal constants'! |
1 | 150 |
|
151 |
noHandlerSignal |
|
44 | 152 |
"return the signal used to handle unhandled signals" |
153 |
||
1 | 154 |
^ NoHandlerSignal |
155 |
! ! |
|
156 |
||
622 | 157 |
!Signal methodsFor:'accessing'! |
1 | 158 |
|
622 | 159 |
errorString |
160 |
"return the notifier string" |
|
1 | 161 |
|
622 | 162 |
^ notifierString |
163 |
! |
|
159 | 164 |
|
622 | 165 |
handlerBlock |
166 |
"return the handlerblock - if non-nil, this will be evaluated with the exception |
|
167 |
object as argument, if no #handle:do: context was found on the stack." |
|
168 |
||
169 |
^ handlerBlock |
|
1 | 170 |
! |
171 |
||
622 | 172 |
handlerBlock:aOneArgBlock |
173 |
"set the handlerblock - this will be evaluated with the exception |
|
174 |
object as argument, if no #handle:do: context was found on the stack." |
|
159 | 175 |
|
622 | 176 |
handlerBlock := aOneArgBlock |
177 |
! |
|
159 | 178 |
|
622 | 179 |
mayProceed |
180 |
"return the signals ability to proceed. |
|
181 |
This flag is (currently) not checked by the system; |
|
182 |
be prepared for changes here, to eventually have nonProceedable |
|
183 |
signals refuse to let you continue execution." |
|
1 | 184 |
|
622 | 185 |
^ mayProceed |
1 | 186 |
! |
187 |
||
188 |
mayProceed:aBoolean |
|
44 | 189 |
"set/clear the signals ability to proceed. |
419 | 190 |
This flag is (currently) not checked by the system; |
191 |
be prepared for changes here, to eventually have nonProceedable |
|
192 |
signals refuse to let you continue execution." |
|
1 | 193 |
|
194 |
mayProceed := aBoolean |
|
195 |
! |
|
196 |
||
622 | 197 |
nameClass:aClass message:aSelector |
198 |
"this sets the class & selector of a method which returns |
|
199 |
that signal - this is simply for documentation purposes - |
|
200 |
see Signal>>printOn: implementation. |
|
201 |
(took me a while to find that one out ;-)" |
|
419 | 202 |
|
622 | 203 |
nameClass := aClass. |
204 |
message := aSelector |
|
419 | 205 |
! |
206 |
||
622 | 207 |
notifierString |
208 |
"return the notifier string" |
|
159 | 209 |
|
622 | 210 |
^ notifierString |
211 |
! |
|
212 |
||
213 |
notifierString:aString |
|
214 |
"set the notifier string" |
|
215 |
||
216 |
notifierString := aString |
|
159 | 217 |
! |
218 |
||
219 |
parent |
|
220 |
"return the parent-signal of the receiver" |
|
221 |
||
222 |
^ parent |
|
223 |
! |
|
224 |
||
622 | 225 |
parent:aSignal |
226 |
"set the parent-signal of the receiver." |
|
227 |
||
228 |
parent := aSignal |
|
229 |
! ! |
|
230 |
||
231 |
!Signal methodsFor:'copying'! |
|
232 |
||
233 |
deepCopy |
|
234 |
"raise an error - deepCopy is not allowed for signals" |
|
1 | 235 |
|
622 | 236 |
^ self deepCopyError |
237 |
! ! |
|
238 |
||
239 |
!Signal methodsFor:'instance creation'! |
|
1 | 240 |
|
622 | 241 |
newSignal |
242 |
"create a new signal, using the receiver as a prototype and |
|
243 |
setting the parent of the new signal to the receiver." |
|
1 | 244 |
|
622 | 245 |
^ (self copy) parent:self |
70 | 246 |
! |
247 |
||
622 | 248 |
newSignalMayProceed:aBoolean |
249 |
"create a new signal, using the receiver as a prototype and |
|
250 |
setting the parent of the new signal to the receiver." |
|
362 | 251 |
|
622 | 252 |
|newSignal| |
70 | 253 |
|
622 | 254 |
newSignal := (self copy) mayProceed:aBoolean. |
255 |
newSignal parent:self. |
|
256 |
^ newSignal |
|
1 | 257 |
! ! |
258 |
||
159 | 259 |
!Signal methodsFor:'printing'! |
260 |
||
261 |
printOn:aStream |
|
262 |
"append a printed representation of the receiver on aStream" |
|
263 |
||
264 |
nameClass notNil ifTrue:[ |
|
265 |
aStream nextPutAll:nameClass name. |
|
266 |
aStream space. |
|
267 |
aStream nextPutAll:message. |
|
268 |
^ self |
|
269 |
]. |
|
270 |
^ super printOn:aStream |
|
271 |
! ! |
|
272 |
||
622 | 273 |
!Signal methodsFor:'private'! |
274 |
||
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
275 |
errorStringFor:errorString with:aParameter |
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
276 |
"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
|
277 |
if the errorString starts with a space, it is appended to the receivers |
622 | 278 |
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
|
279 |
Otherwise, the errorString is returned. |
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
280 |
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
|
281 |
|
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2207
diff
changeset
|
282 |
|t| |
622 | 283 |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
284 |
errorString isNil ifTrue:[ |
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
285 |
t := notifierString |
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
286 |
] ifFalse:[ |
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
287 |
t := errorString |
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
288 |
]. |
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
289 |
|
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
290 |
aParameter isNil ifTrue:[ |
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
291 |
^ t |
622 | 292 |
]. |
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
293 |
|
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
294 |
(t startsWith:' ') ifTrue:[ |
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
295 |
^ aParameter printString , t |
622 | 296 |
]. |
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
297 |
(t endsWith:' ') ifTrue:[ |
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
298 |
^ t , aParameter printString |
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
299 |
]. |
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
300 |
^ t |
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
301 |
|
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
302 |
"Modified: 9.5.1996 / 15:18:58 / cg" |
622 | 303 |
! ! |
304 |
||
305 |
!Signal methodsFor:'queries'! |
|
306 |
||
307 |
accepts:aSignal |
|
308 |
"return true, if the receiver accepts the argument, aSignal. |
|
309 |
(i.e. the receiver is aSignal or a parent of it). False otherwise." |
|
310 |
||
311 |
|s| |
|
312 |
||
313 |
aSignal isQuerySignal ifTrue:[^ false]. |
|
314 |
||
315 |
s := aSignal. |
|
316 |
[s notNil] whileTrue:[ |
|
317 |
self == s ifTrue:[^ true]. |
|
318 |
s := s parent |
|
319 |
]. |
|
320 |
^ false |
|
321 |
! |
|
322 |
||
323 |
inheritsFrom:anotherSignal |
|
324 |
"return true, if the receiver is a child of anotherSignal |
|
325 |
(i.e. if handling anotherSignal also handles the receiver) |
|
326 |
This is almost the same as accepts, but returns false, if |
|
327 |
the receiver is identical to anotherSignal." |
|
328 |
||
329 |
self == anotherSignal ifTrue:[^ false]. |
|
330 |
^ anotherSignal accepts:self |
|
331 |
! |
|
332 |
||
333 |
isHandled |
|
334 |
"return true, if there is a handler for the receiver signal. |
|
335 |
Raising an unhandled signal will usually lead into the debugger, |
|
336 |
but can be cought globally by setting Exceptions EmergencyHandler." |
|
337 |
||
338 |
^ self isHandledIn:(thisContext sender). |
|
339 |
! |
|
340 |
||
341 |
isHandledIn:aContext |
|
342 |
"return true, if there is a handler for the receiver signal in the |
|
343 |
contextChain starting with aContext." |
|
344 |
||
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2207
diff
changeset
|
345 |
|con| |
622 | 346 |
|
347 |
con := aContext. |
|
348 |
[con notNil] whileTrue:[ |
|
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2207
diff
changeset
|
349 |
con := con findNextContextWithSelector:#'handle:do:' or:#'handle:from:do:'. |
2207 | 350 |
con notNil ifTrue:[ |
351 |
" |
|
352 |
is this is a #handle:do: or a #handle:from:do: context |
|
353 |
with self in it ? |
|
354 |
" |
|
355 |
(con receiver accepts:self) ifTrue:[ |
|
356 |
"found a handler context" |
|
622 | 357 |
|
2207 | 358 |
^ true |
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2207
diff
changeset
|
359 |
] |
2207 | 360 |
] |
622 | 361 |
]. |
362 |
^ false |
|
2207 | 363 |
|
364 |
"Modified: 20.1.1997 / 12:45:01 / cg" |
|
622 | 365 |
! |
366 |
||
367 |
isQuerySignal |
|
1249 | 368 |
"return true, if this is a querySignal - always return false here" |
369 |
||
622 | 370 |
^ false |
1249 | 371 |
|
372 |
"Modified: 22.4.1996 / 13:45:06 / cg" |
|
622 | 373 |
! |
374 |
||
375 |
isSignal |
|
376 |
"return true, if the receiver is some kind of signal; |
|
377 |
true returned here - the method is redefined from Object." |
|
378 |
||
379 |
^ true |
|
380 |
! ! |
|
381 |
||
382 |
!Signal methodsFor:'raising'! |
|
383 |
||
384 |
raise |
|
1326 | 385 |
"raise a signal nonproceedable |
386 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
387 |
non proceedable exceptions. |
|
622 | 388 |
The signals notifierString is used as errorString." |
389 |
||
390 |
^ (Exception |
|
1326 | 391 |
signal:self |
392 |
parameter:nil |
|
393 |
errorString:notifierString |
|
394 |
suspendedContext:thisContext sender) raise. |
|
395 |
||
396 |
"Modified: 2.5.1996 / 16:36:23 / cg" |
|
622 | 397 |
! |
398 |
||
399 |
raiseErrorString:aString |
|
1326 | 400 |
"raise a signal nonproceedable. |
401 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
402 |
non proceedable exceptions. |
|
622 | 403 |
The argument is used as errorString." |
404 |
||
405 |
^ (Exception |
|
1326 | 406 |
signal:self |
407 |
parameter:nil |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
408 |
errorString:(self errorStringFor:aString with:nil) |
1326 | 409 |
suspendedContext:thisContext sender) raise. |
410 |
||
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
411 |
"Modified: 9.5.1996 / 15:17:59 / cg" |
622 | 412 |
! |
413 |
||
1610 | 414 |
raiseErrorString:aString in:aContext |
415 |
"raise a signal nonproceedable. |
|
416 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
417 |
non proceedable exceptions. |
|
418 |
The argument is used as errorString. |
|
419 |
The additional context is passed as the context responsible for the raise, |
|
420 |
allowing a raise to mimicri the exception happened somewhere else." |
|
421 |
||
422 |
^ (Exception |
|
423 |
signal:self |
|
424 |
parameter:nil |
|
425 |
errorString:(self errorStringFor:aString with:nil) |
|
426 |
suspendedContext:aContext) raise. |
|
427 |
||
428 |
"Created: 26.7.1996 / 16:42:32 / cg" |
|
429 |
"Modified: 26.7.1996 / 16:42:47 / cg" |
|
430 |
! |
|
431 |
||
622 | 432 |
raiseFrom:something |
1326 | 433 |
"raise a signal nonproceedable. |
434 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
435 |
non proceedable exceptions. |
|
622 | 436 |
The argument, something is passed both as parameter and originator. |
437 |
XXX: I am not certain, if this is the correct behavior (seen in remoteInvocation-goodie)" |
|
438 |
||
439 |
^ (Exception |
|
1326 | 440 |
signal:self |
441 |
parameter:something |
|
442 |
errorString:notifierString |
|
443 |
suspendedContext:thisContext sender |
|
444 |
originator:something) raise. |
|
445 |
||
446 |
"Modified: 2.5.1996 / 16:36:38 / cg" |
|
622 | 447 |
! |
448 |
||
449 |
raiseIn:aContext |
|
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 signals notifierString is used as errorString. |
454 |
The additional context is passed as the context responsible for the raise, |
|
455 |
allowing a raise to mimicri the exception happened somewhere else." |
|
456 |
||
457 |
^ (Exception |
|
1326 | 458 |
signal:self |
459 |
parameter:nil |
|
460 |
errorString:notifierString |
|
461 |
suspendedContext:aContext) raise. |
|
462 |
||
463 |
"Modified: 2.5.1996 / 16:36:44 / cg" |
|
622 | 464 |
! |
465 |
||
466 |
raiseRequest |
|
1326 | 467 |
"raise a signal proceedable. |
622 | 468 |
The signals notifierString is used as errorString." |
469 |
||
470 |
^ (Exception |
|
1326 | 471 |
signal:self |
472 |
parameter:nil |
|
473 |
errorString:notifierString |
|
474 |
suspendedContext:thisContext sender) raiseRequest. |
|
475 |
||
476 |
"Modified: 2.5.1996 / 16:36:52 / cg" |
|
622 | 477 |
! |
478 |
||
479 |
raiseRequestWith:aParameter |
|
1326 | 480 |
"raise a signal proceedable. |
622 | 481 |
The signals notifierString is used as errorString." |
482 |
||
483 |
^ (Exception |
|
1326 | 484 |
signal:self |
485 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
486 |
errorString:(self errorStringFor:nil with:aParameter) |
1326 | 487 |
suspendedContext:thisContext sender) raiseRequest. |
488 |
||
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
489 |
"Modified: 9.5.1996 / 15:13:20 / cg" |
622 | 490 |
! |
491 |
||
492 |
raiseRequestWith:aParameter errorString:aString |
|
1326 | 493 |
"raise a signal proceedable. |
622 | 494 |
The argument, aString is used as errorString." |
495 |
||
496 |
^ (Exception |
|
1326 | 497 |
signal:self |
498 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
499 |
errorString:(self errorStringFor:aString with:aParameter) |
1326 | 500 |
suspendedContext:thisContext sender) raiseRequest |
501 |
||
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
502 |
"Modified: 9.5.1996 / 15:13:35 / cg" |
622 | 503 |
! |
504 |
||
505 |
raiseRequestWith:aParameter errorString:aString in:aContext |
|
1326 | 506 |
"raise a signal proceedable. |
622 | 507 |
The argument, aString is used as errorString. |
1608 | 508 |
The additional context is passed as the context responsible for the raise, |
509 |
allowing a raise to mimicri the exception happened somewhere else." |
|
622 | 510 |
|
511 |
^ (Exception |
|
1326 | 512 |
signal:self |
513 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
514 |
errorString:(self errorStringFor:aString with:aParameter) |
1326 | 515 |
suspendedContext:aContext) raiseRequest |
516 |
||
1608 | 517 |
"Modified: 26.7.1996 / 16:29:27 / cg" |
622 | 518 |
! |
519 |
||
520 |
raiseRequestWith:aParameter in:aContext |
|
1326 | 521 |
"raise a signal proceedable. |
622 | 522 |
The signals notifierString is used as errorString. |
1608 | 523 |
The additional context is passed as the context responsible for the raise, |
524 |
allowing a raise to mimicri the exception happened somewhere else." |
|
622 | 525 |
|
526 |
^ (Exception |
|
1326 | 527 |
signal:self |
528 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
529 |
errorString:(self errorStringFor:nil with:aParameter) |
1326 | 530 |
suspendedContext:aContext) raiseRequest. |
531 |
||
1608 | 532 |
"Modified: 26.7.1996 / 16:29:33 / cg" |
622 | 533 |
! |
534 |
||
535 |
raiseWith:aParameter |
|
1326 | 536 |
"raise a signal nonproceedable. |
537 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
538 |
non proceedable exceptions. |
|
622 | 539 |
The argument, aParameter is passed as parameter. |
540 |
XXX: I am not certain, if this is the correct behavior (seen in remoteInvocation-goodie)" |
|
541 |
||
542 |
^ (Exception |
|
1326 | 543 |
signal:self |
544 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
545 |
errorString:(self errorStringFor:nil with:aParameter) |
1326 | 546 |
suspendedContext:thisContext sender) raise. |
547 |
||
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
548 |
"Modified: 9.5.1996 / 15:14:24 / cg" |
622 | 549 |
! |
550 |
||
551 |
raiseWith:aParameter errorString:aString |
|
1326 | 552 |
"raise a signal nonproceedable |
553 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
554 |
non proceedable exceptions. |
|
622 | 555 |
The argument, aString is used as errorString, aParameter is passed |
556 |
as exception parameter." |
|
557 |
||
558 |
^ (Exception |
|
1326 | 559 |
signal:self |
560 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
561 |
errorString:(self errorStringFor:aString with:aParameter) |
1326 | 562 |
suspendedContext:thisContext sender) raise. |
563 |
||
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
564 |
"Modified: 9.5.1996 / 15:14:32 / cg" |
1326 | 565 |
! |
566 |
||
567 |
raiseWith:aParameter errorString:aString in:aContext |
|
568 |
"raise a signal nonproceedable |
|
569 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
570 |
non proceedable exceptions. |
|
571 |
The argument, aString is used as errorString, aParameter is passed |
|
1608 | 572 |
as exception parameter. |
573 |
The additional context is passed as the context responsible for the raise, |
|
574 |
allowing a raise to mimicri the exception happened somewhere else." |
|
575 |
||
1326 | 576 |
|
577 |
^ (Exception |
|
578 |
signal:self |
|
579 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
580 |
errorString:(self errorStringFor:aString with:aParameter) |
1326 | 581 |
suspendedContext:aContext) raise. |
582 |
||
583 |
"Created: 2.5.1996 / 16:37:25 / cg" |
|
1608 | 584 |
"Modified: 26.7.1996 / 16:29:42 / cg" |
622 | 585 |
! ! |
586 |
||
1 | 587 |
!Signal methodsFor:'save evaluation'! |
588 |
||
622 | 589 |
catch:aBlock |
590 |
"evaluate the argument, aBlock. |
|
591 |
If the receiver-signal is raised during evaluation, abort |
|
592 |
the evaluation and return true; otherwise return false. |
|
593 |
This is the catch & throw mechanism found in other languages, |
|
594 |
where the returned value indicates if an exception occured." |
|
595 |
||
596 |
|raiseOccurred| |
|
597 |
||
598 |
raiseOccurred := false. |
|
599 |
self handle:[:ex | raiseOccurred := true. ex return] do:aBlock. |
|
600 |
^ raiseOccurred |
|
601 |
||
602 |
" |
|
603 |
Object messageNotUnderstoodSignal catch:[ |
|
604 |
123 size open |
|
605 |
] |
|
606 |
" |
|
607 |
! |
|
608 |
||
1 | 609 |
handle:handleBlock do:aBlock |
610 |
"evaluate the argument, aBlock. |
|
611 |
If the receiver-signal is raised during evaluation, |
|
612 |
evaluate the handleBlock passing it an Exception argument. |
|
613 |
The handler may decide how to react to the signal by sending |
|
614 |
a corresponding message to the exception (see there). |
|
615 |
If the signal is not raised, return the value of evaluating |
|
616 |
aBlock." |
|
617 |
||
618 |
^ aBlock value "the real logic is in raise/Exception" |
|
95 | 619 |
|
620 |
" |
|
621 |
Object messageNotUnderstoodSignal handle:[:ex | |
|
159 | 622 |
'oops' printNL. |
623 |
ex return |
|
95 | 624 |
] do:[ |
159 | 625 |
123 size open |
95 | 626 |
] |
627 |
" |
|
120 | 628 |
|
95 | 629 |
" |
630 |
|num| |
|
631 |
||
632 |
num := 0. |
|
633 |
Number divisionByZeroSignal handle:[:ex | |
|
159 | 634 |
'oops' printNL. |
635 |
ex return |
|
95 | 636 |
] do:[ |
159 | 637 |
123 / num |
95 | 638 |
] |
639 |
" |
|
44 | 640 |
! |
641 |
||
362 | 642 |
handle:handleBlock from:anObject do:aBlock |
643 |
"evaluate the argument, aBlock. |
|
644 |
If the receiver-signal is raised during evaluation, |
|
645 |
and the exception originated from anObject, |
|
646 |
evaluate the handleBlock passing it an Exception argument. |
|
647 |
The handler may decide how to react to the signal by sending |
|
648 |
a corresponding message to the exception (see there). |
|
649 |
If the signal is not raised, return the value of evaluating |
|
650 |
aBlock." |
|
651 |
||
652 |
^ aBlock value "the real logic is in raise/Exception" |
|
653 |
||
654 |
" |
|
655 |
the first open will be cought; the second not: |
|
656 |
||
657 |
|o1 o2| |
|
658 |
||
659 |
o1 := 123. |
|
660 |
o2 := nil. |
|
661 |
Object messageNotUnderstoodSignal |
|
662 |
handle: |
|
663 |
[:ex | |
|
664 |
'oops' printNL. |
|
665 |
ex proceed |
|
666 |
] |
|
667 |
from:o1 |
|
668 |
do: |
|
669 |
[ |
|
670 |
o1 open. |
|
671 |
o2 open |
|
672 |
] |
|
673 |
" |
|
674 |
! |
|
675 |
||
419 | 676 |
ignoreIn:aBlock |
159 | 677 |
"evaluate the argument, aBlock. |
678 |
Ignore the receiver-signal during evaluation - i.e. simply |
|
419 | 679 |
continue. |
680 |
This makes only sense for some signals, such as UserInterrupt |
|
681 |
or AbortSignal, because continuing after an exception without any cleanup |
|
682 |
often leads to followup-errors." |
|
159 | 683 |
|
684 |
^ self handle:[:ex | ex proceed] do:aBlock. |
|
685 |
||
686 |
" |
|
419 | 687 |
Object messageNotUnderstoodSignal ignoreIn:[ |
159 | 688 |
123 size open |
61 | 689 |
] |
690 |
" |
|
1 | 691 |
! ! |
692 |
||
2207 | 693 |
!Signal class methodsFor:'documentation'! |
1249 | 694 |
|
695 |
version |
|
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2207
diff
changeset
|
696 |
^ '$Header: /cvs/stx/stx/libbasic/Signal.st,v 1.40 1997-01-28 00:01:20 cg Exp $' |
1249 | 697 |
! ! |
622 | 698 |
Signal initialize! |