author | Stefan Vogel <sv@exept.de> |
Wed, 04 Aug 1999 17:54:19 +0200 | |
changeset 4547 | 082a2f7d9d8e |
parent 4540 | 4b99a82fe85a |
child 4553 | 9b17a621e90f |
permissions | -rw-r--r-- |
1 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
4502 | 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 |
|
4506 | 14 |
instanceVariableNames:'mayProceed notifierString nameClass message handlerBlock parent' |
4518
4716c8d7cb4c
Implement NoHandlerException etc. as class based exceptions.
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
15 |
classVariableNames:'GenericSignal' |
4506 | 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 |
|
4502 | 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 |
|
4502 | 89 |
mayProceed <Boolean> hint for the debugger - program may |
90 |
proceed (currently not honored by the |
|
91 |
debugger) |
|
1275 | 92 |
|
4502 | 93 |
notifierString <String> error message to be output |
70 | 94 |
|
4502 | 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 |
|
4502 | 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 |
|
4502 | 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 |
|
4502 | 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:] |
|
4502 | 119 |
Claus Gittinger |
1292 | 120 |
|
1275 | 121 |
[see also:] |
4502 | 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:'instance creation'! |
1 | 130 |
|
131 |
new |
|
132 |
"return a new signal" |
|
133 |
||
4438 | 134 |
^ (self basicNew) notifierString:'signal'; mayProceed:true |
3004
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
135 |
|
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
136 |
" |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
137 |
Signal new |
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 |
|
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
140 |
"Modified: 8.10.1997 / 11:51:39 / cg" |
1 | 141 |
! ! |
142 |
||
2207 | 143 |
!Signal class methodsFor:'Signal constants'! |
1 | 144 |
|
3004
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
145 |
genericSignal |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
146 |
"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
|
147 |
in the system." |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
148 |
|
4518
4716c8d7cb4c
Implement NoHandlerException etc. as class based exceptions.
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
149 |
^ GenericException |
3004
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
150 |
|
4518
4716c8d7cb4c
Implement NoHandlerException etc. as class based exceptions.
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
151 |
"Created: / 8.10.1997 / 11:46:28 / cg" |
4716c8d7cb4c
Implement NoHandlerException etc. as class based exceptions.
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
152 |
"Modified: / 8.10.1997 / 11:47:08 / cg" |
4716c8d7cb4c
Implement NoHandlerException etc. as class based exceptions.
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
153 |
"Modified: / 4.8.1999 / 08:54:33 / stefan" |
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 |
|
1 | 156 |
noHandlerSignal |
44 | 157 |
"return the signal used to handle unhandled signals" |
158 |
||
4527 | 159 |
^ NoHandlerError |
4518
4716c8d7cb4c
Implement NoHandlerException etc. as class based exceptions.
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
160 |
|
4716c8d7cb4c
Implement NoHandlerException etc. as class based exceptions.
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
161 |
"Modified: / 4.8.1999 / 08:10:09 / stefan" |
4438 | 162 |
! |
163 |
||
164 |
proceedErrorSignal |
|
165 |
"return the signal used to indicate that a handler tried to |
|
166 |
proceed a signal marked as nonproceedable. |
|
167 |
The parameter for the exception raised by this signal is |
|
168 |
the exception which tried to proceed." |
|
169 |
||
4527 | 170 |
^ ProceedError |
4438 | 171 |
|
172 |
"Created: / 27.2.1998 / 14:36:15 / stefan" |
|
4518
4716c8d7cb4c
Implement NoHandlerException etc. as class based exceptions.
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
173 |
"Modified: / 4.8.1999 / 08:00:20 / stefan" |
4438 | 174 |
! |
175 |
||
176 |
wrongProceedabilitySignal |
|
177 |
"return the signal used to indicate that a signaler wants |
|
178 |
to raise a nonproceedable signal proceedable. |
|
179 |
The parameter for the exception raised by this signal is |
|
180 |
the unproceedable signal." |
|
181 |
||
4527 | 182 |
^ WrongProceedabilityError |
4438 | 183 |
|
184 |
"Created: / 27.2.1998 / 14:24:19 / stefan" |
|
4518
4716c8d7cb4c
Implement NoHandlerException etc. as class based exceptions.
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
185 |
"Modified: / 4.8.1999 / 08:03:46 / stefan" |
1 | 186 |
! ! |
187 |
||
622 | 188 |
!Signal methodsFor:'accessing'! |
1 | 189 |
|
622 | 190 |
errorString |
4438 | 191 |
"return the notifier string. |
192 |
If the notifier string starts with space, prepend |
|
193 |
the parents notifier string" |
|
194 |
||
195 |
notifierString isNil ifTrue:[ |
|
196 |
^ parent errorString |
|
197 |
] ifFalse:[ |
|
198 |
(notifierString size > 0 |
|
199 |
and:[notifierString first == (Character space)]) ifTrue:[ |
|
200 |
^ parent errorString, notifierString |
|
201 |
] ifFalse:[ |
|
202 |
^ notifierString |
|
203 |
]. |
|
204 |
] |
|
205 |
||
206 |
" |
|
207 |
Object errorSignal errorString |
|
208 |
" |
|
209 |
||
210 |
"Modified: / 12.3.1998 / 15:04:41 / stefan" |
|
211 |
! |
|
212 |
||
213 |
errorStringExtra:extraString with:aParameter |
|
214 |
"used when raising with a given error string and/or parameter; |
|
215 |
if the errorString starts with a space, it is appended to the receivers |
|
216 |
notifier string; if it ends with a space, it is prepended. |
|
217 |
Otherwise, the extraString is returned. |
|
218 |
If no extraString is given, use the signals default errorString." |
|
219 |
||
220 |
|t| |
|
1 | 221 |
|
4438 | 222 |
(self inheritsFrom:Object userNotificationSignal) ifTrue:[ |
223 |
"/ all userNotifications pass the extraString unchanged. |
|
224 |
^ extraString |
|
225 |
]. |
|
226 |
||
227 |
extraString isNil ifTrue:[ |
|
228 |
t := self errorString |
|
229 |
] ifFalse:[ |
|
230 |
t := extraString. |
|
231 |
(extraString endsWith:Character space) ifTrue:[ |
|
232 |
t := extraString, self errorString |
|
233 |
] ifFalse:[ |
|
234 |
(extraString startsWith:Character space) ifTrue:[ |
|
235 |
t := self errorString, extraString |
|
236 |
] |
|
237 |
]. |
|
238 |
]. |
|
239 |
^ t. |
|
240 |
||
241 |
"/ aParameter isNil ifTrue:[ |
|
242 |
"/ ^ t |
|
243 |
"/ ]. |
|
244 |
"/ |
|
245 |
"/ (t startsWith:' ') ifTrue:[ |
|
246 |
"/ ^ aParameter printString , t |
|
247 |
"/ ]. |
|
248 |
"/ (t endsWith:' ') ifTrue:[ |
|
249 |
"/ ^ t , aParameter printString |
|
250 |
"/ ]. |
|
251 |
"/ ^ t |
|
252 |
||
253 |
"Modified: / 25.3.1997 / 12:12:37 / cg" |
|
254 |
"Created: / 12.3.1998 / 15:11:31 / stefan" |
|
622 | 255 |
! |
159 | 256 |
|
622 | 257 |
handlerBlock |
258 |
"return the handlerblock - if non-nil, this will be evaluated with the exception |
|
259 |
object as argument, if no #handle:do: context was found on the stack." |
|
260 |
||
261 |
^ handlerBlock |
|
1 | 262 |
! |
263 |
||
622 | 264 |
handlerBlock:aOneArgBlock |
265 |
"set the handlerblock - this will be evaluated with the exception |
|
266 |
object as argument, if no #handle:do: context was found on the stack." |
|
159 | 267 |
|
622 | 268 |
handlerBlock := aOneArgBlock |
269 |
! |
|
159 | 270 |
|
622 | 271 |
mayProceed |
272 |
"return the signals ability to proceed. |
|
273 |
This flag is (currently) not checked by the system; |
|
274 |
be prepared for changes here, to eventually have nonProceedable |
|
275 |
signals refuse to let you continue execution." |
|
1 | 276 |
|
622 | 277 |
^ mayProceed |
1 | 278 |
! |
279 |
||
280 |
mayProceed:aBoolean |
|
44 | 281 |
"set/clear the signals ability to proceed. |
419 | 282 |
This flag is (currently) not checked by the system; |
283 |
be prepared for changes here, to eventually have nonProceedable |
|
284 |
signals refuse to let you continue execution." |
|
1 | 285 |
|
286 |
mayProceed := aBoolean |
|
287 |
! |
|
288 |
||
622 | 289 |
nameClass:aClass message:aSelector |
290 |
"this sets the class & selector of a method which returns |
|
291 |
that signal - this is simply for documentation purposes - |
|
292 |
see Signal>>printOn: implementation. |
|
293 |
(took me a while to find that one out ;-)" |
|
419 | 294 |
|
622 | 295 |
nameClass := aClass. |
296 |
message := aSelector |
|
419 | 297 |
! |
298 |
||
622 | 299 |
notifierString |
300 |
"return the notifier string" |
|
159 | 301 |
|
622 | 302 |
^ notifierString |
303 |
! |
|
304 |
||
305 |
notifierString:aString |
|
306 |
"set the notifier string" |
|
307 |
||
308 |
notifierString := aString |
|
159 | 309 |
! |
310 |
||
311 |
parent |
|
312 |
"return the parent-signal of the receiver" |
|
313 |
||
314 |
^ parent |
|
315 |
! |
|
316 |
||
622 | 317 |
parent:aSignal |
318 |
"set the parent-signal of the receiver." |
|
319 |
||
320 |
parent := aSignal |
|
3004
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
321 |
! |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
322 |
|
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
323 |
parent:aSignal mayProceed:aBoolean |
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
324 |
"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
|
325 |
|
3010 | 326 |
parent := aSignal. |
327 |
mayProceed := aBoolean. |
|
3004
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
328 |
|
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
329 |
"Modified: 8.10.1997 / 11:56:11 / cg" |
622 | 330 |
! ! |
331 |
||
332 |
!Signal methodsFor:'copying'! |
|
333 |
||
3348
37b0481be091
must catch #deppCopyUsing: instead of #deepCopy.
Claus Gittinger <cg@exept.de>
parents:
3280
diff
changeset
|
334 |
deepCopyUsing:aDictionary |
622 | 335 |
"raise an error - deepCopy is not allowed for signals" |
1 | 336 |
|
622 | 337 |
^ self deepCopyError |
3348
37b0481be091
must catch #deppCopyUsing: instead of #deepCopy.
Claus Gittinger <cg@exept.de>
parents:
3280
diff
changeset
|
338 |
|
37b0481be091
must catch #deppCopyUsing: instead of #deepCopy.
Claus Gittinger <cg@exept.de>
parents:
3280
diff
changeset
|
339 |
"Created: / 31.3.1998 / 15:43:01 / cg" |
622 | 340 |
! ! |
341 |
||
342 |
!Signal methodsFor:'instance creation'! |
|
1 | 343 |
|
622 | 344 |
newSignal |
345 |
"create a new signal, using the receiver as a prototype and |
|
346 |
setting the parent of the new signal to the receiver." |
|
1 | 347 |
|
3010 | 348 |
^ (self copy) parent:self |
3004
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
349 |
|
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
350 |
"Modified: 8.10.1997 / 11:53:06 / cg" |
70 | 351 |
! |
352 |
||
622 | 353 |
newSignalMayProceed:aBoolean |
354 |
"create a new signal, using the receiver as a prototype and |
|
355 |
setting the parent of the new signal to the receiver." |
|
362 | 356 |
|
3010 | 357 |
^ (self copy) parent:self mayProceed:aBoolean |
70 | 358 |
|
3004
220af5090ec2
added the genericSignal for PP compatiblity
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
359 |
"Modified: 8.10.1997 / 11:57:13 / cg" |
1 | 360 |
! ! |
361 |
||
159 | 362 |
!Signal methodsFor:'printing'! |
363 |
||
364 |
printOn:aStream |
|
365 |
"append a printed representation of the receiver on aStream" |
|
366 |
||
367 |
nameClass notNil ifTrue:[ |
|
4502 | 368 |
aStream nextPutAll:nameClass name. |
369 |
aStream space. |
|
370 |
aStream nextPutAll:message. |
|
371 |
^ self |
|
159 | 372 |
]. |
373 |
^ super printOn:aStream |
|
374 |
! ! |
|
375 |
||
622 | 376 |
!Signal methodsFor:'queries'! |
377 |
||
378 |
accepts:aSignal |
|
379 |
"return true, if the receiver accepts the argument, aSignal. |
|
380 |
(i.e. the receiver is aSignal or a parent of it). False otherwise." |
|
381 |
||
382 |
|s| |
|
383 |
||
4527 | 384 |
self == aSignal ifTrue:[^ true]. |
622 | 385 |
aSignal isQuerySignal ifTrue:[^ false]. |
386 |
||
387 |
s := aSignal. |
|
388 |
[s notNil] whileTrue:[ |
|
4438 | 389 |
self == s ifTrue:[^ true]. |
390 |
s := s parent |
|
622 | 391 |
]. |
392 |
^ false |
|
4438 | 393 |
|
394 |
"Modified: / 22.3.1999 / 12:45:42 / stefan" |
|
622 | 395 |
! |
396 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
397 |
handlerForSignal:signal context:theContext originator:originator |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
398 |
"answer the handler block for the signal from originator. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
399 |
The block is retrieved from aContext. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
400 |
Answer nil if the signal is not handled" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
401 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
402 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
403 |
(theContext selector ~~ #'handle:from:do:' |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
404 |
or:[(theContext argAt:2) == originator]) ifTrue:[ |
4513 | 405 |
(self == signal or:[self accepts:signal]) ifTrue:[ |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
406 |
^ theContext argAt:1 |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
407 |
] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
408 |
]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
409 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
410 |
^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
411 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
412 |
"Created: / 25.7.1999 / 19:55:43 / stefan" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
413 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
414 |
|
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4540
diff
changeset
|
415 |
handlerProtectedBlock:doBlock inContext:context |
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4540
diff
changeset
|
416 |
"set the handlerProtectedBlock in context" |
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4540
diff
changeset
|
417 |
|
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4540
diff
changeset
|
418 |
context selector == #handle:do: ifTrue:[ |
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4540
diff
changeset
|
419 |
context argAt:2 put:doBlock. |
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4540
diff
changeset
|
420 |
] ifFalse:[context selector == #handle:from:do: ifTrue:[ |
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4540
diff
changeset
|
421 |
context argAt:3 put:doBlock. |
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4540
diff
changeset
|
422 |
]]. |
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4540
diff
changeset
|
423 |
|
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4540
diff
changeset
|
424 |
|
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4540
diff
changeset
|
425 |
|
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4540
diff
changeset
|
426 |
! |
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4540
diff
changeset
|
427 |
|
4476 | 428 |
handlingExceptionInContext:theContext |
4473
793078981f01
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
429 |
"answer the handling signal from aContext." |
793078981f01
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
430 |
|
793078981f01
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
431 |
^ self |
793078981f01
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
432 |
! |
793078981f01
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
433 |
|
622 | 434 |
inheritsFrom:anotherSignal |
435 |
"return true, if the receiver is a child of anotherSignal |
|
436 |
(i.e. if handling anotherSignal also handles the receiver) |
|
437 |
This is almost the same as accepts, but returns false, if |
|
438 |
the receiver is identical to anotherSignal." |
|
439 |
||
440 |
self == anotherSignal ifTrue:[^ false]. |
|
441 |
^ anotherSignal accepts:self |
|
3521
4d83701cfc28
care for nil receiver in #isHandledIn:
Claus Gittinger <cg@exept.de>
parents:
3348
diff
changeset
|
442 |
|
4d83701cfc28
care for nil receiver in #isHandledIn:
Claus Gittinger <cg@exept.de>
parents:
3348
diff
changeset
|
443 |
"Modified: / 6.6.1998 / 20:37:47 / cg" |
622 | 444 |
! |
445 |
||
446 |
isHandled |
|
447 |
"return true, if there is a handler for the receiver signal. |
|
448 |
Raising an unhandled signal will usually lead into the debugger, |
|
2689 | 449 |
but can be caught globally by setting Exceptions EmergencyHandler." |
622 | 450 |
|
451 |
^ self isHandledIn:(thisContext sender). |
|
452 |
! |
|
453 |
||
454 |
isHandledIn:aContext |
|
455 |
"return true, if there is a handler for the receiver signal in the |
|
456 |
contextChain starting with aContext." |
|
457 |
||
3521
4d83701cfc28
care for nil receiver in #isHandledIn:
Claus Gittinger <cg@exept.de>
parents:
3348
diff
changeset
|
458 |
|con r| |
622 | 459 |
|
4493 | 460 |
con := Context findFirstSpecialHandle:true raise:false. |
622 | 461 |
[con notNil] whileTrue:[ |
4493 | 462 |
((r := con receiver) notNil |
463 |
and:[(r handlerForSignal:self context:con originator:nil) notNil] |
|
464 |
) ifTrue:[ |
|
465 |
"found a handler context" |
|
466 |
^ true |
|
467 |
]. |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
468 |
con := con findSpecialHandle:true raise:false. |
622 | 469 |
]. |
470 |
^ false |
|
2207 | 471 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
472 |
"Created: / 23.7.1999 / 14:03:34 / stefan" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
473 |
"Modified: / 26.7.1999 / 15:24:34 / stefan" |
622 | 474 |
! |
475 |
||
476 |
isQuerySignal |
|
1249 | 477 |
"return true, if this is a querySignal - always return false here" |
478 |
||
622 | 479 |
^ false |
1249 | 480 |
|
481 |
"Modified: 22.4.1996 / 13:45:06 / cg" |
|
622 | 482 |
! |
483 |
||
484 |
isSignal |
|
485 |
"return true, if the receiver is some kind of signal; |
|
486 |
true returned here - the method is redefined from Object." |
|
487 |
||
488 |
^ true |
|
489 |
! ! |
|
490 |
||
491 |
!Signal methodsFor:'raising'! |
|
492 |
||
4438 | 493 |
newException |
494 |
"answer a new exception object for this signal. |
|
495 |
Subclasses may redefine this method" |
|
496 |
||
4440 | 497 |
^ Exception signal:self originator:nil |
4438 | 498 |
|
499 |
"Created: / 26.2.1998 / 19:53:56 / stefan" |
|
4440 | 500 |
"Modified: / 23.7.1999 / 13:41:00 / stefan" |
4438 | 501 |
! |
502 |
||
503 |
newExceptionFrom:originator |
|
504 |
"answer a new exception object for this signal. |
|
505 |
Set the originator. |
|
506 |
Subclasses may redefine this method" |
|
507 |
||
4440 | 508 |
^ Exception signal:self originator:originator |
4438 | 509 |
|
510 |
"Created: / 27.2.1998 / 09:17:00 / stefan" |
|
4440 | 511 |
"Modified: / 23.7.1999 / 13:41:15 / stefan" |
4438 | 512 |
! |
513 |
||
622 | 514 |
raise |
4438 | 515 |
"raise a signal nonproceedable. |
622 | 516 |
The signals notifierString is used as errorString." |
517 |
||
4540
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
518 |
^ self newException |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
519 |
suspendedContext:thisContext sender; |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
520 |
raise |
1326 | 521 |
|
4438 | 522 |
"Modified: / 2.5.1996 / 16:36:23 / cg" |
523 |
"Modified: / 5.3.1998 / 16:44:36 / stefan" |
|
622 | 524 |
! |
525 |
||
526 |
raiseErrorString:aString |
|
1326 | 527 |
"raise a signal nonproceedable. |
622 | 528 |
The argument is used as errorString." |
529 |
||
4540
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
530 |
^ self newException |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
531 |
suspendedContext:thisContext sender; |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
532 |
errorString:aString; |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
533 |
raise. |
1326 | 534 |
|
4438 | 535 |
"Modified: / 9.5.1996 / 15:17:59 / cg" |
536 |
"Modified: / 12.3.1998 / 15:15:22 / stefan" |
|
622 | 537 |
! |
538 |
||
1610 | 539 |
raiseErrorString:aString in:aContext |
540 |
"raise a signal nonproceedable. |
|
541 |
The argument is used as errorString. |
|
542 |
The additional context is passed as the context responsible for the raise, |
|
543 |
allowing a raise to mimicri the exception happened somewhere else." |
|
544 |
||
4438 | 545 |
^ (self newException |
546 |
signal:self |
|
547 |
parameter:nil |
|
548 |
errorString:aString |
|
549 |
suspendedContext:aContext |
|
550 |
originator:nil) raise. |
|
1610 | 551 |
|
4438 | 552 |
"Created: / 26.7.1996 / 16:42:32 / cg" |
553 |
"Modified: / 26.7.1996 / 16:42:47 / cg" |
|
554 |
"Modified: / 12.3.1998 / 15:43:43 / stefan" |
|
1610 | 555 |
! |
556 |
||
622 | 557 |
raiseFrom:something |
1326 | 558 |
"raise a signal nonproceedable. |
4438 | 559 |
The argument, something is passed both as parameter and originator." |
622 | 560 |
|
4540
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
561 |
^ (self newExceptionFrom:something) |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
562 |
suspendedContext:thisContext sender; |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
563 |
parameter:something; |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
564 |
raise |
1326 | 565 |
|
4438 | 566 |
"Modified: / 2.5.1996 / 16:36:38 / cg" |
567 |
"Modified: / 5.3.1998 / 16:49:55 / stefan" |
|
622 | 568 |
! |
569 |
||
570 |
raiseIn:aContext |
|
1326 | 571 |
"raise a signal nonproceedable. |
622 | 572 |
The signals notifierString is used as errorString. |
573 |
The additional context is passed as the context responsible for the raise, |
|
574 |
allowing a raise to mimicri the exception happened somewhere else." |
|
575 |
||
4540
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
576 |
^ self newException |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
577 |
suspendedContext:aContext; |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
578 |
raise. |
1326 | 579 |
|
4438 | 580 |
"Modified: / 2.5.1996 / 16:36:44 / cg" |
581 |
"Modified: / 5.3.1998 / 16:50:21 / stefan" |
|
622 | 582 |
! |
583 |
||
584 |
raiseRequest |
|
1326 | 585 |
"raise a signal proceedable. |
622 | 586 |
The signals notifierString is used as errorString." |
587 |
||
4438 | 588 |
^ self newException raiseRequest. |
1326 | 589 |
|
4438 | 590 |
"Modified: / 2.5.1996 / 16:36:52 / cg" |
591 |
"Modified: / 5.3.1998 / 16:50:46 / stefan" |
|
622 | 592 |
! |
593 |
||
3103 | 594 |
raiseRequestFrom:something |
595 |
"raise a signal proceedable. |
|
4438 | 596 |
The argument, something is passed both as parameter and originator." |
3103 | 597 |
|
4438 | 598 |
^ ((self newExceptionFrom:something) parameter:something) raiseRequest. |
3103 | 599 |
|
4438 | 600 |
"Modified: / 2.5.1996 / 16:36:38 / cg" |
601 |
"Modified: / 5.3.1998 / 16:52:46 / stefan" |
|
3103 | 602 |
! |
603 |
||
622 | 604 |
raiseRequestWith:aParameter |
1326 | 605 |
"raise a signal proceedable. |
622 | 606 |
The signals notifierString is used as errorString." |
607 |
||
4438 | 608 |
^ (self newException parameter:aParameter) raiseRequest. |
1326 | 609 |
|
4438 | 610 |
"Modified: / 9.5.1996 / 15:13:20 / cg" |
611 |
"Modified: / 12.3.1998 / 15:16:57 / stefan" |
|
622 | 612 |
! |
613 |
||
614 |
raiseRequestWith:aParameter errorString:aString |
|
1326 | 615 |
"raise a signal proceedable. |
622 | 616 |
The argument, aString is used as errorString." |
617 |
||
4438 | 618 |
^ (self newException |
619 |
parameter:aParameter; |
|
620 |
errorString:aString |
|
621 |
) raiseRequest |
|
1326 | 622 |
|
4438 | 623 |
"Modified: / 9.5.1996 / 15:13:35 / cg" |
624 |
"Modified: / 12.3.1998 / 15:17:52 / stefan" |
|
622 | 625 |
! |
626 |
||
627 |
raiseRequestWith:aParameter errorString:aString in:aContext |
|
1326 | 628 |
"raise a signal proceedable. |
622 | 629 |
The argument, aString is used as errorString. |
1608 | 630 |
The additional context is passed as the context responsible for the raise, |
631 |
allowing a raise to mimicri the exception happened somewhere else." |
|
622 | 632 |
|
4438 | 633 |
^ (self newException |
634 |
parameter:aParameter; |
|
635 |
errorString:aString; |
|
636 |
suspendedContext:aContext) raiseRequest |
|
1326 | 637 |
|
4438 | 638 |
"Modified: / 26.7.1996 / 16:29:27 / cg" |
639 |
"Modified: / 12.3.1998 / 15:18:34 / stefan" |
|
622 | 640 |
! |
641 |
||
642 |
raiseRequestWith:aParameter in:aContext |
|
1326 | 643 |
"raise a signal proceedable. |
622 | 644 |
The signals notifierString is used as errorString. |
1608 | 645 |
The additional context is passed as the context responsible for the raise, |
646 |
allowing a raise to mimicri the exception happened somewhere else." |
|
622 | 647 |
|
4438 | 648 |
^ (self newException |
649 |
parameter:aParameter; |
|
650 |
suspendedContext:aContext) raiseRequest. |
|
1326 | 651 |
|
4438 | 652 |
"Modified: / 26.7.1996 / 16:29:33 / cg" |
653 |
"Modified: / 12.3.1998 / 15:18:55 / stefan" |
|
622 | 654 |
! |
655 |
||
656 |
raiseWith:aParameter |
|
1326 | 657 |
"raise a signal nonproceedable. |
4438 | 658 |
The argument, aParameter is passed as parameter." |
622 | 659 |
|
4540
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
660 |
^ self newException |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
661 |
suspendedContext:thisContext sender; |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
662 |
parameter:aParameter; |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
663 |
raise. |
1326 | 664 |
|
4438 | 665 |
"Modified: / 9.5.1996 / 15:14:24 / cg" |
666 |
"Modified: / 12.3.1998 / 15:19:11 / stefan" |
|
622 | 667 |
! |
668 |
||
669 |
raiseWith:aParameter errorString:aString |
|
4438 | 670 |
"raise a signal nonproceedable. |
622 | 671 |
The argument, aString is used as errorString, aParameter is passed |
672 |
as exception parameter." |
|
673 |
||
4540
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
674 |
^ self newException |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
675 |
suspendedContext:thisContext sender; |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
676 |
parameter:aParameter; |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
677 |
errorString:aString; |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
678 |
raise. |
1326 | 679 |
|
4438 | 680 |
"Modified: / 9.5.1996 / 15:14:32 / cg" |
681 |
"Modified: / 12.3.1998 / 15:19:40 / stefan" |
|
1326 | 682 |
! |
683 |
||
684 |
raiseWith:aParameter errorString:aString in:aContext |
|
4438 | 685 |
"raise a signal nonproceedable. |
1326 | 686 |
The argument, aString is used as errorString, aParameter is passed |
1608 | 687 |
as exception parameter. |
688 |
The additional context is passed as the context responsible for the raise, |
|
689 |
allowing a raise to mimicri the exception happened somewhere else." |
|
690 |
||
1326 | 691 |
|
4540
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
692 |
^ self newException |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
693 |
parameter:aParameter; |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
694 |
errorString:aString; |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
695 |
suspendedContext:aContext; |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
696 |
raise. |
1326 | 697 |
|
4438 | 698 |
"Created: / 2.5.1996 / 16:37:25 / cg" |
699 |
"Modified: / 26.7.1996 / 16:29:42 / cg" |
|
700 |
"Modified: / 12.3.1998 / 15:20:12 / stefan" |
|
3157 | 701 |
! |
702 |
||
703 |
raiseWith:aParameter in:aContext |
|
704 |
"raise a signal nonproceedable. |
|
4438 | 705 |
The argument, aParameter is passed as parameter." |
3157 | 706 |
|
4540
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
707 |
^ self newException |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
708 |
parameter:aParameter; |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
709 |
suspendedContext:aContext; |
4b99a82fe85a
suspendedContext setup explicit
Claus Gittinger <cg@exept.de>
parents:
4527
diff
changeset
|
710 |
raise. |
3157 | 711 |
|
712 |
"Modified: / 9.5.1996 / 15:14:24 / cg" |
|
713 |
"Created: / 4.1.1998 / 14:38:15 / cg" |
|
4438 | 714 |
"Modified: / 12.3.1998 / 15:34:51 / stefan" |
622 | 715 |
! ! |
716 |
||
1 | 717 |
!Signal methodsFor:'save evaluation'! |
718 |
||
622 | 719 |
catch:aBlock |
720 |
"evaluate the argument, aBlock. |
|
721 |
If the receiver-signal is raised during evaluation, abort |
|
722 |
the evaluation and return true; otherwise return false. |
|
723 |
This is the catch & throw mechanism found in other languages, |
|
724 |
where the returned value indicates if an exception occured." |
|
725 |
||
726 |
|raiseOccurred| |
|
727 |
||
728 |
raiseOccurred := false. |
|
729 |
self handle:[:ex | raiseOccurred := true. ex return] do:aBlock. |
|
730 |
^ raiseOccurred |
|
731 |
||
732 |
" |
|
733 |
Object messageNotUnderstoodSignal catch:[ |
|
4502 | 734 |
123 size open |
622 | 735 |
] |
736 |
" |
|
737 |
! |
|
738 |
||
1 | 739 |
handle:handleBlock do:aBlock |
740 |
"evaluate the argument, aBlock. |
|
741 |
If the receiver-signal is raised during evaluation, |
|
742 |
evaluate the handleBlock passing it an Exception argument. |
|
743 |
The handler may decide how to react to the signal by sending |
|
744 |
a corresponding message to the exception (see there). |
|
745 |
If the signal is not raised, return the value of evaluating |
|
746 |
aBlock." |
|
747 |
||
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4540
diff
changeset
|
748 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
749 |
<exception: #handle> |
95 | 750 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
751 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
752 |
^ aBlock value "the real logic is in Exception>>doRaise" |
120 | 753 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
754 |
" |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
755 |
Object messageNotUnderstoodSignal handle:[:ex | |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
756 |
'oops' printNL. |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
757 |
ex return |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
758 |
] do:[ |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
759 |
123 size open |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
760 |
] |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
761 |
" |
95 | 762 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
763 |
" |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
764 |
|num| |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
765 |
|
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
766 |
num := 0. |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
767 |
Number divisionByZeroSignal handle:[:ex | |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
768 |
'oops' printNL. |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
769 |
ex return |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
770 |
] do:[ |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
771 |
123 / num |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
772 |
] |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
773 |
" |
4438 | 774 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
775 |
"Modified: / 25.7.1999 / 19:43:01 / stefan" |
44 | 776 |
! |
777 |
||
362 | 778 |
handle:handleBlock from:anObject do:aBlock |
779 |
"evaluate the argument, aBlock. |
|
780 |
If the receiver-signal is raised during evaluation, |
|
781 |
and the exception originated from anObject, |
|
782 |
evaluate the handleBlock passing it an Exception argument. |
|
783 |
The handler may decide how to react to the signal by sending |
|
784 |
a corresponding message to the exception (see there). |
|
785 |
If the signal is not raised, return the value of evaluating |
|
786 |
aBlock." |
|
787 |
||
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4540
diff
changeset
|
788 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
789 |
<exception: #handle> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
790 |
|
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
791 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
792 |
^ aBlock value "the real logic is in Exception>>doRaise" |
362 | 793 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
794 |
" |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
795 |
the first open will be caught; the second not: |
362 | 796 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
797 |
|o1 o2| |
362 | 798 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
799 |
o1 := 123. |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
800 |
o2 := nil. |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
801 |
Object messageNotUnderstoodSignal |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
802 |
handle: |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
803 |
[:ex | |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
804 |
'oops' printNL. |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
805 |
ex proceed |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
806 |
] |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
807 |
from:o1 |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
808 |
do: |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
809 |
[ |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
810 |
o1 open. |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
811 |
o2 open |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
812 |
] |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4486
diff
changeset
|
813 |
" |
4438 | 814 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4440
diff
changeset
|
815 |
"Modified: / 25.7.1999 / 19:43:40 / stefan" |
362 | 816 |
! |
817 |
||
419 | 818 |
ignoreIn:aBlock |
159 | 819 |
"evaluate the argument, aBlock. |
820 |
Ignore the receiver-signal during evaluation - i.e. simply |
|
419 | 821 |
continue. |
822 |
This makes only sense for some signals, such as UserInterrupt |
|
823 |
or AbortSignal, because continuing after an exception without any cleanup |
|
824 |
often leads to followup-errors." |
|
159 | 825 |
|
4486
f84def7aaf3f
replaced #proceed with #proceedWith:nil
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
826 |
^ self handle:[:ex | ex proceedWith:nil] do:aBlock. |
159 | 827 |
|
828 |
" |
|
419 | 829 |
Object messageNotUnderstoodSignal ignoreIn:[ |
4486
f84def7aaf3f
replaced #proceed with #proceedWith:nil
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
830 |
123 size open |
61 | 831 |
] |
832 |
" |
|
1 | 833 |
! ! |
834 |
||
2207 | 835 |
!Signal class methodsFor:'documentation'! |
1249 | 836 |
|
837 |
version |
|
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4540
diff
changeset
|
838 |
^ '$Header: /cvs/stx/stx/libbasic/Signal.st,v 1.67 1999-08-04 15:54:19 stefan Exp $' |
1249 | 839 |
! ! |