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