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