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