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