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