author | ca |
Thu, 05 Feb 1998 20:04:33 +0100 | |
changeset 3280 | 11acfea80af7 |
parent 3157 | b8dd7d5fedd2 |
child 3348 | 37b0481be091 |
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 |
|
3157 | 89 |
mayProceed <Boolean> hint for the debugger - program may |
90 |
proceed (currently not honored by the |
|
91 |
debugger) |
|
1275 | 92 |
|
3157 | 93 |
notifierString <String> error message to be output |
70 | 94 |
|
3157 | 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 |
|
3157 | 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 |
|
3157 | 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. |
|
1275 | 108 |
|
109 |
[Class variables:] |
|
70 | 110 |
|
3157 | 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:] |
|
3157 | 119 |
Claus Gittinger |
1292 | 120 |
|
1275 | 121 |
[see also:] |
3157 | 122 |
Exception |
123 |
SignalSet QuerySignal |
|
124 |
Object |
|
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:[ |
3157 | 135 |
GenericSignal := self basicNew notifierString: 'unknown Signal with: '. |
136 |
GenericSignal nameClass:self message:#genericSignal. |
|
3004
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:[ |
3157 | 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:[ |
3157 | 150 |
NoHandlerSignal := ErrorSignal newSignalMayProceed:true. |
151 |
NoHandlerSignal nameClass:self message:#noHandlerSignal. |
|
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 |
|
3280
11acfea80af7
all notification signals pass the errorString unchanged.
ca
parents:
3157
diff
changeset
|
326 |
(self inheritsFrom:Object userNotificationSignal) ifTrue:[ |
11acfea80af7
all notification signals pass the errorString unchanged.
ca
parents:
3157
diff
changeset
|
327 |
"/ all userNotifications pass the errorString unchanged. |
11acfea80af7
all notification signals pass the errorString unchanged.
ca
parents:
3157
diff
changeset
|
328 |
^ errorString |
11acfea80af7
all notification signals pass the errorString unchanged.
ca
parents:
3157
diff
changeset
|
329 |
]. |
11acfea80af7
all notification signals pass the errorString unchanged.
ca
parents:
3157
diff
changeset
|
330 |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
331 |
errorString isNil ifTrue:[ |
3280
11acfea80af7
all notification signals pass the errorString unchanged.
ca
parents:
3157
diff
changeset
|
332 |
t := notifierString |
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
333 |
] ifFalse:[ |
3280
11acfea80af7
all notification signals pass the errorString unchanged.
ca
parents:
3157
diff
changeset
|
334 |
t := errorString. |
11acfea80af7
all notification signals pass the errorString unchanged.
ca
parents:
3157
diff
changeset
|
335 |
(errorString endsWith:Character space) ifTrue:[ |
11acfea80af7
all notification signals pass the errorString unchanged.
ca
parents:
3157
diff
changeset
|
336 |
t := errorString , notifierString |
11acfea80af7
all notification signals pass the errorString unchanged.
ca
parents:
3157
diff
changeset
|
337 |
] ifFalse:[ |
11acfea80af7
all notification signals pass the errorString unchanged.
ca
parents:
3157
diff
changeset
|
338 |
(errorString startsWith:Character space) ifTrue:[ |
11acfea80af7
all notification signals pass the errorString unchanged.
ca
parents:
3157
diff
changeset
|
339 |
t := notifierString , errorString |
11acfea80af7
all notification signals pass the errorString unchanged.
ca
parents:
3157
diff
changeset
|
340 |
] |
11acfea80af7
all notification signals pass the errorString unchanged.
ca
parents:
3157
diff
changeset
|
341 |
]. |
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
342 |
]. |
2497 | 343 |
^ t. |
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
344 |
|
2497 | 345 |
"/ aParameter isNil ifTrue:[ |
346 |
"/ ^ t |
|
347 |
"/ ]. |
|
348 |
"/ |
|
349 |
"/ (t startsWith:' ') ifTrue:[ |
|
350 |
"/ ^ aParameter printString , t |
|
351 |
"/ ]. |
|
352 |
"/ (t endsWith:' ') ifTrue:[ |
|
353 |
"/ ^ t , aParameter printString |
|
354 |
"/ ]. |
|
355 |
"/ ^ t |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
356 |
|
2497 | 357 |
"Modified: 25.3.1997 / 12:12:37 / cg" |
622 | 358 |
! ! |
359 |
||
360 |
!Signal methodsFor:'queries'! |
|
361 |
||
362 |
accepts:aSignal |
|
363 |
"return true, if the receiver accepts the argument, aSignal. |
|
364 |
(i.e. the receiver is aSignal or a parent of it). False otherwise." |
|
365 |
||
366 |
|s| |
|
367 |
||
368 |
aSignal isQuerySignal ifTrue:[^ false]. |
|
369 |
||
370 |
s := aSignal. |
|
371 |
[s notNil] whileTrue:[ |
|
372 |
self == s ifTrue:[^ true]. |
|
373 |
s := s parent |
|
374 |
]. |
|
375 |
^ false |
|
376 |
! |
|
377 |
||
378 |
inheritsFrom:anotherSignal |
|
379 |
"return true, if the receiver is a child of anotherSignal |
|
380 |
(i.e. if handling anotherSignal also handles the receiver) |
|
381 |
This is almost the same as accepts, but returns false, if |
|
382 |
the receiver is identical to anotherSignal." |
|
383 |
||
384 |
self == anotherSignal ifTrue:[^ false]. |
|
385 |
^ anotherSignal accepts:self |
|
386 |
! |
|
387 |
||
388 |
isHandled |
|
389 |
"return true, if there is a handler for the receiver signal. |
|
390 |
Raising an unhandled signal will usually lead into the debugger, |
|
2689 | 391 |
but can be caught globally by setting Exceptions EmergencyHandler." |
622 | 392 |
|
393 |
^ self isHandledIn:(thisContext sender). |
|
394 |
! |
|
395 |
||
396 |
isHandledIn:aContext |
|
397 |
"return true, if there is a handler for the receiver signal in the |
|
398 |
contextChain starting with aContext." |
|
399 |
||
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2207
diff
changeset
|
400 |
|con| |
622 | 401 |
|
402 |
con := aContext. |
|
403 |
[con notNil] whileTrue:[ |
|
3157 | 404 |
con := con findNextContextWithSelector:#'handle:do:' or:#'handle:from:do:' or:nil. |
405 |
con notNil ifTrue:[ |
|
406 |
" |
|
407 |
is this is a #handle:do: or a #handle:from:do: context |
|
408 |
with self in it ? |
|
409 |
" |
|
410 |
(con receiver accepts:self) ifTrue:[ |
|
411 |
"found a handler context" |
|
622 | 412 |
|
3157 | 413 |
^ true |
414 |
] |
|
415 |
] |
|
622 | 416 |
]. |
417 |
^ false |
|
2207 | 418 |
|
419 |
"Modified: 20.1.1997 / 12:45:01 / cg" |
|
622 | 420 |
! |
421 |
||
422 |
isQuerySignal |
|
1249 | 423 |
"return true, if this is a querySignal - always return false here" |
424 |
||
622 | 425 |
^ false |
1249 | 426 |
|
427 |
"Modified: 22.4.1996 / 13:45:06 / cg" |
|
622 | 428 |
! |
429 |
||
430 |
isSignal |
|
431 |
"return true, if the receiver is some kind of signal; |
|
432 |
true returned here - the method is redefined from Object." |
|
433 |
||
434 |
^ true |
|
435 |
! ! |
|
436 |
||
437 |
!Signal methodsFor:'raising'! |
|
438 |
||
439 |
raise |
|
1326 | 440 |
"raise a signal nonproceedable |
441 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
442 |
non proceedable exceptions. |
|
622 | 443 |
The signals notifierString is used as errorString." |
444 |
||
445 |
^ (Exception |
|
3157 | 446 |
signal:self |
447 |
parameter:nil |
|
448 |
errorString:notifierString |
|
449 |
suspendedContext:thisContext sender) raise. |
|
1326 | 450 |
|
451 |
"Modified: 2.5.1996 / 16:36:23 / cg" |
|
622 | 452 |
! |
453 |
||
454 |
raiseErrorString:aString |
|
1326 | 455 |
"raise a signal nonproceedable. |
456 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
457 |
non proceedable exceptions. |
|
622 | 458 |
The argument is used as errorString." |
459 |
||
460 |
^ (Exception |
|
3157 | 461 |
signal:self |
462 |
parameter:nil |
|
463 |
errorString:(self errorStringFor:aString with:nil) |
|
464 |
suspendedContext:thisContext sender) raise. |
|
1326 | 465 |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
466 |
"Modified: 9.5.1996 / 15:17:59 / cg" |
622 | 467 |
! |
468 |
||
1610 | 469 |
raiseErrorString:aString in:aContext |
470 |
"raise a signal nonproceedable. |
|
471 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
472 |
non proceedable exceptions. |
|
473 |
The argument is used as errorString. |
|
474 |
The additional context is passed as the context responsible for the raise, |
|
475 |
allowing a raise to mimicri the exception happened somewhere else." |
|
476 |
||
477 |
^ (Exception |
|
3157 | 478 |
signal:self |
479 |
parameter:nil |
|
480 |
errorString:(self errorStringFor:aString with:nil) |
|
481 |
suspendedContext:aContext) raise. |
|
1610 | 482 |
|
483 |
"Created: 26.7.1996 / 16:42:32 / cg" |
|
484 |
"Modified: 26.7.1996 / 16:42:47 / cg" |
|
485 |
! |
|
486 |
||
622 | 487 |
raiseFrom:something |
1326 | 488 |
"raise a signal nonproceedable. |
489 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
490 |
non proceedable exceptions. |
|
622 | 491 |
The argument, something is passed both as parameter and originator. |
492 |
XXX: I am not certain, if this is the correct behavior (seen in remoteInvocation-goodie)" |
|
493 |
||
494 |
^ (Exception |
|
3157 | 495 |
signal:self |
496 |
parameter:something |
|
497 |
errorString:notifierString |
|
498 |
suspendedContext:thisContext sender |
|
499 |
originator:something) raise. |
|
1326 | 500 |
|
501 |
"Modified: 2.5.1996 / 16:36:38 / cg" |
|
622 | 502 |
! |
503 |
||
504 |
raiseIn:aContext |
|
1326 | 505 |
"raise a signal nonproceedable. |
506 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
507 |
non proceedable exceptions. |
|
622 | 508 |
The signals notifierString is used as errorString. |
509 |
The additional context is passed as the context responsible for the raise, |
|
510 |
allowing a raise to mimicri the exception happened somewhere else." |
|
511 |
||
512 |
^ (Exception |
|
3157 | 513 |
signal:self |
514 |
parameter:nil |
|
515 |
errorString:notifierString |
|
516 |
suspendedContext:aContext) raise. |
|
1326 | 517 |
|
518 |
"Modified: 2.5.1996 / 16:36:44 / cg" |
|
622 | 519 |
! |
520 |
||
521 |
raiseRequest |
|
1326 | 522 |
"raise a signal proceedable. |
622 | 523 |
The signals notifierString is used as errorString." |
524 |
||
525 |
^ (Exception |
|
3157 | 526 |
signal:self |
527 |
parameter:nil |
|
528 |
errorString:notifierString |
|
529 |
suspendedContext:thisContext sender) raiseRequest. |
|
1326 | 530 |
|
531 |
"Modified: 2.5.1996 / 16:36:52 / cg" |
|
622 | 532 |
! |
533 |
||
3103 | 534 |
raiseRequestFrom:something |
535 |
"raise a signal proceedable. |
|
536 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
537 |
non proceedable exceptions. |
|
538 |
The argument, something is passed both as parameter and originator. |
|
539 |
XXX: I am not certain, if this is the correct behavior (seen in remoteInvocation-goodie)" |
|
540 |
||
541 |
^ (Exception |
|
3157 | 542 |
signal:self |
543 |
parameter:something |
|
544 |
errorString:notifierString |
|
545 |
suspendedContext:thisContext sender |
|
546 |
originator:something) raise. |
|
3103 | 547 |
|
548 |
"Modified: 2.5.1996 / 16:36:38 / cg" |
|
549 |
! |
|
550 |
||
622 | 551 |
raiseRequestWith:aParameter |
1326 | 552 |
"raise a signal proceedable. |
622 | 553 |
The signals notifierString is used as errorString." |
554 |
||
555 |
^ (Exception |
|
3157 | 556 |
signal:self |
557 |
parameter:aParameter |
|
558 |
errorString:(self errorStringFor:nil with:aParameter) |
|
559 |
suspendedContext:thisContext sender) raiseRequest. |
|
1326 | 560 |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
561 |
"Modified: 9.5.1996 / 15:13:20 / cg" |
622 | 562 |
! |
563 |
||
564 |
raiseRequestWith:aParameter errorString:aString |
|
1326 | 565 |
"raise a signal proceedable. |
622 | 566 |
The argument, aString is used as errorString." |
567 |
||
568 |
^ (Exception |
|
3157 | 569 |
signal:self |
570 |
parameter:aParameter |
|
571 |
errorString:(self errorStringFor:aString with:aParameter) |
|
572 |
suspendedContext:thisContext sender) raiseRequest |
|
1326 | 573 |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
574 |
"Modified: 9.5.1996 / 15:13:35 / cg" |
622 | 575 |
! |
576 |
||
577 |
raiseRequestWith:aParameter errorString:aString in:aContext |
|
1326 | 578 |
"raise a signal proceedable. |
622 | 579 |
The argument, aString is used as errorString. |
1608 | 580 |
The additional context is passed as the context responsible for the raise, |
581 |
allowing a raise to mimicri the exception happened somewhere else." |
|
622 | 582 |
|
583 |
^ (Exception |
|
3157 | 584 |
signal:self |
585 |
parameter:aParameter |
|
586 |
errorString:(self errorStringFor:aString with:aParameter) |
|
587 |
suspendedContext:aContext) raiseRequest |
|
1326 | 588 |
|
1608 | 589 |
"Modified: 26.7.1996 / 16:29:27 / cg" |
622 | 590 |
! |
591 |
||
592 |
raiseRequestWith:aParameter in:aContext |
|
1326 | 593 |
"raise a signal proceedable. |
622 | 594 |
The signals notifierString is used as errorString. |
1608 | 595 |
The additional context is passed as the context responsible for the raise, |
596 |
allowing a raise to mimicri the exception happened somewhere else." |
|
622 | 597 |
|
598 |
^ (Exception |
|
3157 | 599 |
signal:self |
600 |
parameter:aParameter |
|
601 |
errorString:(self errorStringFor:nil with:aParameter) |
|
602 |
suspendedContext:aContext) raiseRequest. |
|
1326 | 603 |
|
1608 | 604 |
"Modified: 26.7.1996 / 16:29:33 / cg" |
622 | 605 |
! |
606 |
||
607 |
raiseWith:aParameter |
|
1326 | 608 |
"raise a signal nonproceedable. |
609 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
610 |
non proceedable exceptions. |
|
622 | 611 |
The argument, aParameter is passed as parameter. |
612 |
XXX: I am not certain, if this is the correct behavior (seen in remoteInvocation-goodie)" |
|
613 |
||
614 |
^ (Exception |
|
3157 | 615 |
signal:self |
616 |
parameter:aParameter |
|
617 |
errorString:(self errorStringFor:nil with:aParameter) |
|
618 |
suspendedContext:thisContext sender) raise. |
|
1326 | 619 |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
620 |
"Modified: 9.5.1996 / 15:14:24 / cg" |
622 | 621 |
! |
622 |
||
623 |
raiseWith:aParameter errorString:aString |
|
1326 | 624 |
"raise a signal nonproceedable |
625 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
626 |
non proceedable exceptions. |
|
622 | 627 |
The argument, aString is used as errorString, aParameter is passed |
628 |
as exception parameter." |
|
629 |
||
630 |
^ (Exception |
|
3157 | 631 |
signal:self |
632 |
parameter:aParameter |
|
633 |
errorString:(self errorStringFor:aString with:aParameter) |
|
634 |
suspendedContext:thisContext sender) raise. |
|
1326 | 635 |
|
1362
36e887173783
dok & errorString passing fixed (include parameter)
Claus Gittinger <cg@exept.de>
parents:
1326
diff
changeset
|
636 |
"Modified: 9.5.1996 / 15:14:32 / cg" |
1326 | 637 |
! |
638 |
||
639 |
raiseWith:aParameter errorString:aString in:aContext |
|
640 |
"raise a signal nonproceedable |
|
641 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
642 |
non proceedable exceptions. |
|
643 |
The argument, aString is used as errorString, aParameter is passed |
|
1608 | 644 |
as exception parameter. |
645 |
The additional context is passed as the context responsible for the raise, |
|
646 |
allowing a raise to mimicri the exception happened somewhere else." |
|
647 |
||
1326 | 648 |
|
649 |
^ (Exception |
|
3157 | 650 |
signal:self |
651 |
parameter:aParameter |
|
652 |
errorString:(self errorStringFor:aString with:aParameter) |
|
653 |
suspendedContext:aContext) raise. |
|
1326 | 654 |
|
655 |
"Created: 2.5.1996 / 16:37:25 / cg" |
|
1608 | 656 |
"Modified: 26.7.1996 / 16:29:42 / cg" |
3157 | 657 |
! |
658 |
||
659 |
raiseWith:aParameter in:aContext |
|
660 |
"raise a signal nonproceedable. |
|
661 |
- notice, ST/X does not (for now) distinguish between proceedable and |
|
662 |
non proceedable exceptions. |
|
663 |
The argument, aParameter is passed as parameter. |
|
664 |
XXX: I am not certain, if this is the correct behavior (seen in remoteInvocation-goodie)" |
|
665 |
||
666 |
^ (Exception |
|
667 |
signal:self |
|
668 |
parameter:aParameter |
|
669 |
errorString:(self errorStringFor:nil with:aParameter) |
|
670 |
suspendedContext:aContext) raise. |
|
671 |
||
672 |
"Modified: / 9.5.1996 / 15:14:24 / cg" |
|
673 |
"Created: / 4.1.1998 / 14:38:15 / cg" |
|
622 | 674 |
! ! |
675 |
||
1 | 676 |
!Signal methodsFor:'save evaluation'! |
677 |
||
622 | 678 |
catch:aBlock |
679 |
"evaluate the argument, aBlock. |
|
680 |
If the receiver-signal is raised during evaluation, abort |
|
681 |
the evaluation and return true; otherwise return false. |
|
682 |
This is the catch & throw mechanism found in other languages, |
|
683 |
where the returned value indicates if an exception occured." |
|
684 |
||
685 |
|raiseOccurred| |
|
686 |
||
687 |
raiseOccurred := false. |
|
688 |
self handle:[:ex | raiseOccurred := true. ex return] do:aBlock. |
|
689 |
^ raiseOccurred |
|
690 |
||
691 |
" |
|
692 |
Object messageNotUnderstoodSignal catch:[ |
|
693 |
123 size open |
|
694 |
] |
|
695 |
" |
|
696 |
! |
|
697 |
||
1 | 698 |
handle:handleBlock do:aBlock |
699 |
"evaluate the argument, aBlock. |
|
700 |
If the receiver-signal is raised during evaluation, |
|
701 |
evaluate the handleBlock passing it an Exception argument. |
|
702 |
The handler may decide how to react to the signal by sending |
|
703 |
a corresponding message to the exception (see there). |
|
704 |
If the signal is not raised, return the value of evaluating |
|
705 |
aBlock." |
|
706 |
||
707 |
^ aBlock value "the real logic is in raise/Exception" |
|
95 | 708 |
|
709 |
" |
|
710 |
Object messageNotUnderstoodSignal handle:[:ex | |
|
159 | 711 |
'oops' printNL. |
712 |
ex return |
|
95 | 713 |
] do:[ |
159 | 714 |
123 size open |
95 | 715 |
] |
716 |
" |
|
120 | 717 |
|
95 | 718 |
" |
719 |
|num| |
|
720 |
||
721 |
num := 0. |
|
722 |
Number divisionByZeroSignal handle:[:ex | |
|
159 | 723 |
'oops' printNL. |
724 |
ex return |
|
95 | 725 |
] do:[ |
159 | 726 |
123 / num |
95 | 727 |
] |
728 |
" |
|
44 | 729 |
! |
730 |
||
362 | 731 |
handle:handleBlock from:anObject do:aBlock |
732 |
"evaluate the argument, aBlock. |
|
733 |
If the receiver-signal is raised during evaluation, |
|
734 |
and the exception originated from anObject, |
|
735 |
evaluate the handleBlock passing it an Exception argument. |
|
736 |
The handler may decide how to react to the signal by sending |
|
737 |
a corresponding message to the exception (see there). |
|
738 |
If the signal is not raised, return the value of evaluating |
|
739 |
aBlock." |
|
740 |
||
741 |
^ aBlock value "the real logic is in raise/Exception" |
|
742 |
||
743 |
" |
|
2689 | 744 |
the first open will be caught; the second not: |
362 | 745 |
|
746 |
|o1 o2| |
|
747 |
||
748 |
o1 := 123. |
|
749 |
o2 := nil. |
|
750 |
Object messageNotUnderstoodSignal |
|
751 |
handle: |
|
752 |
[:ex | |
|
753 |
'oops' printNL. |
|
754 |
ex proceed |
|
755 |
] |
|
756 |
from:o1 |
|
757 |
do: |
|
758 |
[ |
|
759 |
o1 open. |
|
760 |
o2 open |
|
761 |
] |
|
762 |
" |
|
763 |
! |
|
764 |
||
419 | 765 |
ignoreIn:aBlock |
159 | 766 |
"evaluate the argument, aBlock. |
767 |
Ignore the receiver-signal during evaluation - i.e. simply |
|
419 | 768 |
continue. |
769 |
This makes only sense for some signals, such as UserInterrupt |
|
770 |
or AbortSignal, because continuing after an exception without any cleanup |
|
771 |
often leads to followup-errors." |
|
159 | 772 |
|
773 |
^ self handle:[:ex | ex proceed] do:aBlock. |
|
774 |
||
775 |
" |
|
419 | 776 |
Object messageNotUnderstoodSignal ignoreIn:[ |
159 | 777 |
123 size open |
61 | 778 |
] |
779 |
" |
|
1 | 780 |
! ! |
781 |
||
2207 | 782 |
!Signal class methodsFor:'documentation'! |
1249 | 783 |
|
784 |
version |
|
3280
11acfea80af7
all notification signals pass the errorString unchanged.
ca
parents:
3157
diff
changeset
|
785 |
^ '$Header: /cvs/stx/stx/libbasic/Signal.st,v 1.49 1998-02-05 19:04:33 ca Exp $' |
1249 | 786 |
! ! |
622 | 787 |
Signal initialize! |