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