1
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
Object subclass:#Exception
|
44
|
14 |
instanceVariableNames:'signal parameter errorString
|
|
15 |
suspendedContext handlerContext
|
1
|
16 |
resumeBlock rejectBlock'
|
12
|
17 |
classVariableNames:'EmergencyHandler'
|
1
|
18 |
poolDictionaries:''
|
|
19 |
category:'Kernel-Exceptions'
|
|
20 |
!
|
|
21 |
|
|
22 |
Exception comment:'
|
|
23 |
|
|
24 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
25 |
All Rights Reserved
|
|
26 |
|
54
|
27 |
$Header: /cvs/stx/stx/libbasic/Exception.st,v 1.6 1994-02-25 12:57:09 claus Exp $
|
12
|
28 |
'!
|
|
29 |
|
|
30 |
!Exception class methodsFor:'documentation'!
|
|
31 |
|
|
32 |
documentation
|
|
33 |
"
|
1
|
34 |
Instances of Exception are passed to a Signal handling block as argument.
|
|
35 |
The handler block may perform various actions by sending corresponding messages
|
|
36 |
to the exception handler. The following actions are possible:
|
|
37 |
|
|
38 |
reject - dont handle this signal;
|
|
39 |
another handler will be searched for,
|
|
40 |
upper in the calling hierarchy
|
|
41 |
|
|
42 |
proceed - continue after the Signal>>raise, returning nil as value
|
|
43 |
proceedWith:val - same, but return val from Signal>>raise
|
|
44 |
|
|
45 |
return - return from the Signal>>handle:do:, returning nil as value
|
|
46 |
return:val - same, but return val from Signal>>handle:do:
|
|
47 |
|
|
48 |
restart - restart the Signal>>handle:do:, after repairing
|
|
49 |
|
|
50 |
Via the Exception object, the handler can also query the state of execution,
|
44
|
51 |
where the Signal was raised, where the handler is, the signal which caused
|
|
52 |
the error and the errorString passed when the signal was raised:
|
|
53 |
|
|
54 |
instance variables:
|
|
55 |
signal - the signal which caused the exception
|
|
56 |
parameter - a parameter (if any) which was passed when raising
|
|
57 |
the signal (only if raised with #raiseWith:aParameter)
|
|
58 |
|
|
59 |
errorString - an errorString (only if raised wiith #raiseWith:errorString:)
|
|
60 |
suspendedContext- the context where the signal raise occured
|
|
61 |
handlerContext - the context of the handler itself
|
|
62 |
|
|
63 |
resumeBlock - private to the exception; needed to perform resume action
|
|
64 |
rejectBlock - private to the exception; needed to perfomr reject action
|
|
65 |
|
|
66 |
No Emergency mechanism is currently implemented - an unhandled signal currently
|
|
67 |
goes always into the debugger; the method found dealing with it exist only
|
|
68 |
for compatibility reasons only.
|
54
|
69 |
|
|
70 |
instance variables:
|
|
71 |
signal <Signal> the signal which is responsible for all of this
|
|
72 |
parameter <Object> the parameter passed to raiseRequestWith: or nil (for raise)
|
|
73 |
errorString <String> the signals notifierString, or the string given to raise
|
|
74 |
suspendedContext <Context> the context, in which the raise occured
|
|
75 |
|
|
76 |
handlerContext <Context> the handlers (if found) context
|
|
77 |
resumeBlock <Block> used during handler evaluation to get back
|
|
78 |
rejectBlock <Block> used during handler evaluation to reject
|
|
79 |
|
|
80 |
Class variables:
|
|
81 |
EmergencyHandler <Block> this block is evaluated, if no handler was defined
|
|
82 |
for a signal (i.e. this one is responsible for the
|
|
83 |
unhandled exception debugger).
|
|
84 |
Having this being a block allows to globally catch
|
|
85 |
these errors - even if cought by someone not nesting
|
|
86 |
around the erronous code (as the catch/through does).
|
12
|
87 |
"
|
|
88 |
! !
|
3
|
89 |
|
12
|
90 |
!Exception class methodsFor:'initialization'!
|
|
91 |
|
|
92 |
initialize
|
|
93 |
EmergencyHandler := [:ex :con |
|
54
|
94 |
"
|
12
|
95 |
(ex signal) error:('unhandled exception: ' , ex signal notifierString)
|
54
|
96 |
"
|
|
97 |
(ex signal) enterDebuggerWith:('unhandled exception: ' , ex errorString).
|
12
|
98 |
]
|
|
99 |
! !
|
|
100 |
|
|
101 |
!Exception class methodsFor:'defaults'!
|
|
102 |
|
|
103 |
emergencyHandler
|
|
104 |
"return the handler used for unhandled exceptions"
|
|
105 |
|
|
106 |
^ EmergencyHandler
|
|
107 |
!
|
|
108 |
|
|
109 |
emergencyHandler:aTwoArgBlock
|
|
110 |
"set the handler used for unhandled exceptions"
|
|
111 |
|
|
112 |
EmergencyHandler := aTwoArgBlock
|
|
113 |
! !
|
1
|
114 |
|
|
115 |
!Exception methodsFor:'accessing'!
|
|
116 |
|
|
117 |
signal
|
|
118 |
"return the signal, that caused the exception"
|
|
119 |
|
|
120 |
^ signal
|
|
121 |
!
|
|
122 |
|
44
|
123 |
parameter
|
|
124 |
"return the parameter passsed with the signal raise
|
|
125 |
(or nil, if there was none)"
|
1
|
126 |
|
|
127 |
^ parameter
|
|
128 |
!
|
|
129 |
|
44
|
130 |
errorString
|
|
131 |
"return the errorString passsed with the signal raise
|
|
132 |
(or nil, if there was none)"
|
|
133 |
|
|
134 |
^ errorString
|
|
135 |
!
|
|
136 |
|
|
137 |
handlerContext
|
|
138 |
"return the context of the handler"
|
|
139 |
|
|
140 |
^ handlerContext
|
|
141 |
!
|
|
142 |
|
1
|
143 |
suspendedContext
|
44
|
144 |
"return the context in which the raise occured"
|
|
145 |
|
|
146 |
^ suspendedContext
|
1
|
147 |
! !
|
|
148 |
|
|
149 |
!Exception methodsFor:'setup'!
|
|
150 |
|
44
|
151 |
signal:aSignal parameter:aParameter errorString:aString suspendedContext:sContext
|
|
152 |
"set the fields usable for inspection by the handler
|
|
153 |
- only to be sent from the signal when raising"
|
1
|
154 |
|
44
|
155 |
signal := aSignal.
|
|
156 |
parameter := aParameter.
|
|
157 |
errorString := aString.
|
|
158 |
suspendedContext := sContext.
|
1
|
159 |
!
|
|
160 |
|
|
161 |
handlerContext:aContext
|
44
|
162 |
"set the context of the handler.
|
|
163 |
- only to be sent from the signal when raising"
|
1
|
164 |
|
|
165 |
handlerContext := aContext
|
|
166 |
!
|
|
167 |
|
|
168 |
rejectBlock:aBlock
|
|
169 |
"this is meant to be sent by Signal only"
|
|
170 |
|
|
171 |
rejectBlock := aBlock
|
|
172 |
!
|
|
173 |
|
|
174 |
resumeBlock:aBlock
|
|
175 |
"this is meant to be sent by Signal only"
|
|
176 |
|
|
177 |
resumeBlock := aBlock
|
|
178 |
! !
|
|
179 |
|
|
180 |
!Exception methodsFor:'handler actions'!
|
|
181 |
|
|
182 |
reject
|
|
183 |
"handler decided not to handle this signal -
|
|
184 |
system will look for another handler"
|
|
185 |
|
|
186 |
rejectBlock value
|
|
187 |
!
|
|
188 |
|
|
189 |
resume
|
|
190 |
"Continue after the raise - the raise returns nil"
|
|
191 |
|
|
192 |
resumeBlock value:nil
|
|
193 |
!
|
|
194 |
|
|
195 |
resumeWith:value
|
|
196 |
"Continue after the raise - the raise returns value"
|
|
197 |
|
|
198 |
resumeBlock value:value
|
|
199 |
!
|
|
200 |
|
|
201 |
proceed
|
|
202 |
"Continue after the raise - the raise returns nil"
|
|
203 |
|
|
204 |
resumeBlock value:nil
|
|
205 |
!
|
|
206 |
|
|
207 |
proceedWith:value
|
|
208 |
"Continue after the raise - the raise returns value"
|
|
209 |
|
|
210 |
resumeBlock value:value
|
|
211 |
!
|
|
212 |
|
|
213 |
return
|
|
214 |
"Continue after the handle:do: - the handle:do: returns nil"
|
|
215 |
|
|
216 |
handlerContext resume
|
|
217 |
!
|
|
218 |
|
|
219 |
returnWith:value
|
|
220 |
"Continue after the handle:do: - the handle:do: returns value"
|
|
221 |
|
|
222 |
handlerContext resume:value
|
|
223 |
!
|
|
224 |
|
|
225 |
restart
|
|
226 |
"restart the handle:do: - usually after some repair work is done
|
|
227 |
in handler"
|
|
228 |
|
|
229 |
handlerContext restart
|
|
230 |
! !
|