author | Claus Gittinger <cg@exept.de> |
Fri, 18 Apr 1997 21:05:22 +0200 | |
changeset 2568 | 9b7a3a08b8ca |
parent 2497 | 5aaa953d3e40 |
child 2689 | ada9b102abcf |
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:[ |
2497 | 287 |
t := errorString. |
288 |
(errorString endsWith:Character space) ifTrue:[ |
|
289 |
t := errorString , notifierString |
|
290 |
] ifFalse:[ |
|
291 |
(errorString startsWith:Character space) ifTrue:[ |
|
292 |
t := notifierString , errorString |
|
293 |
] |
|
294 |
]. |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
295 |
]. |
2497 | 296 |
^ t. |
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
297 |
|
2497 | 298 |
"/ aParameter isNil ifTrue:[ |
299 |
"/ ^ t |
|
300 |
"/ ]. |
|
301 |
"/ |
|
302 |
"/ (t startsWith:' ') ifTrue:[ |
|
303 |
"/ ^ aParameter printString , t |
|
304 |
"/ ]. |
|
305 |
"/ (t endsWith:' ') ifTrue:[ |
|
306 |
"/ ^ t , aParameter printString |
|
307 |
"/ ]. |
|
308 |
"/ ^ t |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
309 |
|
2497 | 310 |
"Modified: 25.3.1997 / 12:12:37 / cg" |
622 | 311 |
! ! |
312 |
||
313 |
!Signal methodsFor:'queries'! |
|
314 |
||
315 |
accepts:aSignal |
|
316 |
"return true, if the receiver accepts the argument, aSignal. |
|
317 |
(i.e. the receiver is aSignal or a parent of it). False otherwise." |
|
318 |
||
319 |
|s| |
|
320 |
||
321 |
aSignal isQuerySignal ifTrue:[^ false]. |
|
322 |
||
323 |
s := aSignal. |
|
324 |
[s notNil] whileTrue:[ |
|
325 |
self == s ifTrue:[^ true]. |
|
326 |
s := s parent |
|
327 |
]. |
|
328 |
^ false |
|
329 |
! |
|
330 |
||
331 |
inheritsFrom:anotherSignal |
|
332 |
"return true, if the receiver is a child of anotherSignal |
|
333 |
(i.e. if handling anotherSignal also handles the receiver) |
|
334 |
This is almost the same as accepts, but returns false, if |
|
335 |
the receiver is identical to anotherSignal." |
|
336 |
||
337 |
self == anotherSignal ifTrue:[^ false]. |
|
338 |
^ anotherSignal accepts:self |
|
339 |
! |
|
340 |
||
341 |
isHandled |
|
342 |
"return true, if there is a handler for the receiver signal. |
|
343 |
Raising an unhandled signal will usually lead into the debugger, |
|
344 |
but can be cought globally by setting Exceptions EmergencyHandler." |
|
345 |
||
346 |
^ self isHandledIn:(thisContext sender). |
|
347 |
! |
|
348 |
||
349 |
isHandledIn:aContext |
|
350 |
"return true, if there is a handler for the receiver signal in the |
|
351 |
contextChain starting with aContext." |
|
352 |
||
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2207
diff
changeset
|
353 |
|con| |
622 | 354 |
|
355 |
con := aContext. |
|
356 |
[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
|
357 |
con := con findNextContextWithSelector:#'handle:do:' or:#'handle:from:do:'. |
2207 | 358 |
con notNil ifTrue:[ |
359 |
" |
|
360 |
is this is a #handle:do: or a #handle:from:do: context |
|
361 |
with self in it ? |
|
362 |
" |
|
363 |
(con receiver accepts:self) ifTrue:[ |
|
364 |
"found a handler context" |
|
622 | 365 |
|
2207 | 366 |
^ true |
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2207
diff
changeset
|
367 |
] |
2207 | 368 |
] |
622 | 369 |
]. |
370 |
^ false |
|
2207 | 371 |
|
372 |
"Modified: 20.1.1997 / 12:45:01 / cg" |
|
622 | 373 |
! |
374 |
||
375 |
isQuerySignal |
|
1249 | 376 |
"return true, if this is a querySignal - always return false here" |
377 |
||
622 | 378 |
^ false |
1249 | 379 |
|
380 |
"Modified: 22.4.1996 / 13:45:06 / cg" |
|
622 | 381 |
! |
382 |
||
383 |
isSignal |
|
384 |
"return true, if the receiver is some kind of signal; |
|
385 |
true returned here - the method is redefined from Object." |
|
386 |
||
387 |
^ true |
|
388 |
! ! |
|
389 |
||
390 |
!Signal methodsFor:'raising'! |
|
391 |
||
392 |
raise |
|
1326 | 393 |
"raise a signal nonproceedable |
394 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
395 |
non proceedable exceptions. |
|
622 | 396 |
The signals notifierString is used as errorString." |
397 |
||
398 |
^ (Exception |
|
1326 | 399 |
signal:self |
400 |
parameter:nil |
|
401 |
errorString:notifierString |
|
402 |
suspendedContext:thisContext sender) raise. |
|
403 |
||
404 |
"Modified: 2.5.1996 / 16:36:23 / cg" |
|
622 | 405 |
! |
406 |
||
407 |
raiseErrorString:aString |
|
1326 | 408 |
"raise a signal nonproceedable. |
409 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
410 |
non proceedable exceptions. |
|
622 | 411 |
The argument is used as errorString." |
412 |
||
413 |
^ (Exception |
|
1326 | 414 |
signal:self |
415 |
parameter:nil |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
416 |
errorString:(self errorStringFor:aString with:nil) |
1326 | 417 |
suspendedContext:thisContext sender) raise. |
418 |
||
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
419 |
"Modified: 9.5.1996 / 15:17:59 / cg" |
622 | 420 |
! |
421 |
||
1610 | 422 |
raiseErrorString:aString in:aContext |
423 |
"raise a signal nonproceedable. |
|
424 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
425 |
non proceedable exceptions. |
|
426 |
The argument is used as errorString. |
|
427 |
The additional context is passed as the context responsible for the raise, |
|
428 |
allowing a raise to mimicri the exception happened somewhere else." |
|
429 |
||
430 |
^ (Exception |
|
431 |
signal:self |
|
432 |
parameter:nil |
|
433 |
errorString:(self errorStringFor:aString with:nil) |
|
434 |
suspendedContext:aContext) raise. |
|
435 |
||
436 |
"Created: 26.7.1996 / 16:42:32 / cg" |
|
437 |
"Modified: 26.7.1996 / 16:42:47 / cg" |
|
438 |
! |
|
439 |
||
622 | 440 |
raiseFrom:something |
1326 | 441 |
"raise a signal nonproceedable. |
442 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
443 |
non proceedable exceptions. |
|
622 | 444 |
The argument, something is passed both as parameter and originator. |
445 |
XXX: I am not certain, if this is the correct behavior (seen in remoteInvocation-goodie)" |
|
446 |
||
447 |
^ (Exception |
|
1326 | 448 |
signal:self |
449 |
parameter:something |
|
450 |
errorString:notifierString |
|
451 |
suspendedContext:thisContext sender |
|
452 |
originator:something) raise. |
|
453 |
||
454 |
"Modified: 2.5.1996 / 16:36:38 / cg" |
|
622 | 455 |
! |
456 |
||
457 |
raiseIn:aContext |
|
1326 | 458 |
"raise a signal nonproceedable. |
459 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
460 |
non proceedable exceptions. |
|
622 | 461 |
The signals notifierString is used as errorString. |
462 |
The additional context is passed as the context responsible for the raise, |
|
463 |
allowing a raise to mimicri the exception happened somewhere else." |
|
464 |
||
465 |
^ (Exception |
|
1326 | 466 |
signal:self |
467 |
parameter:nil |
|
468 |
errorString:notifierString |
|
469 |
suspendedContext:aContext) raise. |
|
470 |
||
471 |
"Modified: 2.5.1996 / 16:36:44 / cg" |
|
622 | 472 |
! |
473 |
||
474 |
raiseRequest |
|
1326 | 475 |
"raise a signal proceedable. |
622 | 476 |
The signals notifierString is used as errorString." |
477 |
||
478 |
^ (Exception |
|
1326 | 479 |
signal:self |
480 |
parameter:nil |
|
481 |
errorString:notifierString |
|
482 |
suspendedContext:thisContext sender) raiseRequest. |
|
483 |
||
484 |
"Modified: 2.5.1996 / 16:36:52 / cg" |
|
622 | 485 |
! |
486 |
||
487 |
raiseRequestWith:aParameter |
|
1326 | 488 |
"raise a signal proceedable. |
622 | 489 |
The signals notifierString is used as errorString." |
490 |
||
491 |
^ (Exception |
|
1326 | 492 |
signal:self |
493 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
494 |
errorString:(self errorStringFor:nil with:aParameter) |
1326 | 495 |
suspendedContext:thisContext sender) raiseRequest. |
496 |
||
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
497 |
"Modified: 9.5.1996 / 15:13:20 / cg" |
622 | 498 |
! |
499 |
||
500 |
raiseRequestWith:aParameter errorString:aString |
|
1326 | 501 |
"raise a signal proceedable. |
622 | 502 |
The argument, aString is used as errorString." |
503 |
||
504 |
^ (Exception |
|
1326 | 505 |
signal:self |
506 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
507 |
errorString:(self errorStringFor:aString with:aParameter) |
1326 | 508 |
suspendedContext:thisContext sender) raiseRequest |
509 |
||
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
510 |
"Modified: 9.5.1996 / 15:13:35 / cg" |
622 | 511 |
! |
512 |
||
513 |
raiseRequestWith:aParameter errorString:aString in:aContext |
|
1326 | 514 |
"raise a signal proceedable. |
622 | 515 |
The argument, aString is used as errorString. |
1608 | 516 |
The additional context is passed as the context responsible for the raise, |
517 |
allowing a raise to mimicri the exception happened somewhere else." |
|
622 | 518 |
|
519 |
^ (Exception |
|
1326 | 520 |
signal:self |
521 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
522 |
errorString:(self errorStringFor:aString with:aParameter) |
1326 | 523 |
suspendedContext:aContext) raiseRequest |
524 |
||
1608 | 525 |
"Modified: 26.7.1996 / 16:29:27 / cg" |
622 | 526 |
! |
527 |
||
528 |
raiseRequestWith:aParameter in:aContext |
|
1326 | 529 |
"raise a signal proceedable. |
622 | 530 |
The signals notifierString is used as errorString. |
1608 | 531 |
The additional context is passed as the context responsible for the raise, |
532 |
allowing a raise to mimicri the exception happened somewhere else." |
|
622 | 533 |
|
534 |
^ (Exception |
|
1326 | 535 |
signal:self |
536 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
537 |
errorString:(self errorStringFor:nil with:aParameter) |
1326 | 538 |
suspendedContext:aContext) raiseRequest. |
539 |
||
1608 | 540 |
"Modified: 26.7.1996 / 16:29:33 / cg" |
622 | 541 |
! |
542 |
||
543 |
raiseWith:aParameter |
|
1326 | 544 |
"raise a signal nonproceedable. |
545 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
546 |
non proceedable exceptions. |
|
622 | 547 |
The argument, aParameter is passed as parameter. |
548 |
XXX: I am not certain, if this is the correct behavior (seen in remoteInvocation-goodie)" |
|
549 |
||
550 |
^ (Exception |
|
1326 | 551 |
signal:self |
552 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
553 |
errorString:(self errorStringFor:nil with:aParameter) |
1326 | 554 |
suspendedContext:thisContext sender) raise. |
555 |
||
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
556 |
"Modified: 9.5.1996 / 15:14:24 / cg" |
622 | 557 |
! |
558 |
||
559 |
raiseWith:aParameter errorString:aString |
|
1326 | 560 |
"raise a signal nonproceedable |
561 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
562 |
non proceedable exceptions. |
|
622 | 563 |
The argument, aString is used as errorString, aParameter is passed |
564 |
as exception parameter." |
|
565 |
||
566 |
^ (Exception |
|
1326 | 567 |
signal:self |
568 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
569 |
errorString:(self errorStringFor:aString with:aParameter) |
1326 | 570 |
suspendedContext:thisContext sender) raise. |
571 |
||
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
572 |
"Modified: 9.5.1996 / 15:14:32 / cg" |
1326 | 573 |
! |
574 |
||
575 |
raiseWith:aParameter errorString:aString in:aContext |
|
576 |
"raise a signal nonproceedable |
|
577 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
578 |
non proceedable exceptions. |
|
579 |
The argument, aString is used as errorString, aParameter is passed |
|
1608 | 580 |
as exception parameter. |
581 |
The additional context is passed as the context responsible for the raise, |
|
582 |
allowing a raise to mimicri the exception happened somewhere else." |
|
583 |
||
1326 | 584 |
|
585 |
^ (Exception |
|
586 |
signal:self |
|
587 |
parameter:aParameter |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
588 |
errorString:(self errorStringFor:aString with:aParameter) |
1326 | 589 |
suspendedContext:aContext) raise. |
590 |
||
591 |
"Created: 2.5.1996 / 16:37:25 / cg" |
|
1608 | 592 |
"Modified: 26.7.1996 / 16:29:42 / cg" |
622 | 593 |
! ! |
594 |
||
1 | 595 |
!Signal methodsFor:'save evaluation'! |
596 |
||
622 | 597 |
catch:aBlock |
598 |
"evaluate the argument, aBlock. |
|
599 |
If the receiver-signal is raised during evaluation, abort |
|
600 |
the evaluation and return true; otherwise return false. |
|
601 |
This is the catch & throw mechanism found in other languages, |
|
602 |
where the returned value indicates if an exception occured." |
|
603 |
||
604 |
|raiseOccurred| |
|
605 |
||
606 |
raiseOccurred := false. |
|
607 |
self handle:[:ex | raiseOccurred := true. ex return] do:aBlock. |
|
608 |
^ raiseOccurred |
|
609 |
||
610 |
" |
|
611 |
Object messageNotUnderstoodSignal catch:[ |
|
612 |
123 size open |
|
613 |
] |
|
614 |
" |
|
615 |
! |
|
616 |
||
1 | 617 |
handle:handleBlock do:aBlock |
618 |
"evaluate the argument, aBlock. |
|
619 |
If the receiver-signal is raised during evaluation, |
|
620 |
evaluate the handleBlock passing it an Exception argument. |
|
621 |
The handler may decide how to react to the signal by sending |
|
622 |
a corresponding message to the exception (see there). |
|
623 |
If the signal is not raised, return the value of evaluating |
|
624 |
aBlock." |
|
625 |
||
626 |
^ aBlock value "the real logic is in raise/Exception" |
|
95 | 627 |
|
628 |
" |
|
629 |
Object messageNotUnderstoodSignal handle:[:ex | |
|
159 | 630 |
'oops' printNL. |
631 |
ex return |
|
95 | 632 |
] do:[ |
159 | 633 |
123 size open |
95 | 634 |
] |
635 |
" |
|
120 | 636 |
|
95 | 637 |
" |
638 |
|num| |
|
639 |
||
640 |
num := 0. |
|
641 |
Number divisionByZeroSignal handle:[:ex | |
|
159 | 642 |
'oops' printNL. |
643 |
ex return |
|
95 | 644 |
] do:[ |
159 | 645 |
123 / num |
95 | 646 |
] |
647 |
" |
|
44 | 648 |
! |
649 |
||
362 | 650 |
handle:handleBlock from:anObject do:aBlock |
651 |
"evaluate the argument, aBlock. |
|
652 |
If the receiver-signal is raised during evaluation, |
|
653 |
and the exception originated from anObject, |
|
654 |
evaluate the handleBlock passing it an Exception argument. |
|
655 |
The handler may decide how to react to the signal by sending |
|
656 |
a corresponding message to the exception (see there). |
|
657 |
If the signal is not raised, return the value of evaluating |
|
658 |
aBlock." |
|
659 |
||
660 |
^ aBlock value "the real logic is in raise/Exception" |
|
661 |
||
662 |
" |
|
663 |
the first open will be cought; the second not: |
|
664 |
||
665 |
|o1 o2| |
|
666 |
||
667 |
o1 := 123. |
|
668 |
o2 := nil. |
|
669 |
Object messageNotUnderstoodSignal |
|
670 |
handle: |
|
671 |
[:ex | |
|
672 |
'oops' printNL. |
|
673 |
ex proceed |
|
674 |
] |
|
675 |
from:o1 |
|
676 |
do: |
|
677 |
[ |
|
678 |
o1 open. |
|
679 |
o2 open |
|
680 |
] |
|
681 |
" |
|
682 |
! |
|
683 |
||
419 | 684 |
ignoreIn:aBlock |
159 | 685 |
"evaluate the argument, aBlock. |
686 |
Ignore the receiver-signal during evaluation - i.e. simply |
|
419 | 687 |
continue. |
688 |
This makes only sense for some signals, such as UserInterrupt |
|
689 |
or AbortSignal, because continuing after an exception without any cleanup |
|
690 |
often leads to followup-errors." |
|
159 | 691 |
|
692 |
^ self handle:[:ex | ex proceed] do:aBlock. |
|
693 |
||
694 |
" |
|
419 | 695 |
Object messageNotUnderstoodSignal ignoreIn:[ |
159 | 696 |
123 size open |
61 | 697 |
] |
698 |
" |
|
1 | 699 |
! ! |
700 |
||
2207 | 701 |
!Signal class methodsFor:'documentation'! |
1249 | 702 |
|
703 |
version |
|
2497 | 704 |
^ '$Header: /cvs/stx/stx/libbasic/Signal.st,v 1.41 1997-03-25 11:42:00 cg Exp $' |
1249 | 705 |
! ! |
622 | 706 |
Signal initialize! |