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