author | Claus Gittinger <cg@exept.de> |
Tue, 01 Feb 2000 22:52:44 +0100 | |
changeset 5225 | d74b4c895376 |
parent 4937 | 7e723f1daca7 |
child 5295 | f144309dab04 |
permissions | -rw-r--r-- |
4554 | 1 |
" |
2 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
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 |
||
14 |
||
4528 | 15 |
GenericException subclass:#NoHandlerError |
16 |
instanceVariableNames:'' |
|
17 |
classVariableNames:'EmergencyHandler' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Kernel-Exceptions' |
|
20 |
! |
|
21 |
||
22 |
!NoHandlerError class methodsFor:'documentation'! |
|
23 |
||
4554 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
27 |
All Rights Reserved |
|
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 |
||
38 |
! |
|
39 |
||
4528 | 40 |
documentation |
41 |
" |
|
42 |
NoHandlerError is raised, if there is no exception handler |
|
43 |
or default action for an exception. |
|
44 |
||
45 |
The parameter is the unhandled exception. |
|
4554 | 46 |
|
47 |
[Class variables:] |
|
48 |
EmergencyHandler <Block> this block is evaluated, if no handler was defined |
|
49 |
for a signal (i.e. this one is responsible for the |
|
50 |
unhandled exception debugger). |
|
51 |
Having this being a block allows to globally catch |
|
52 |
these errors - even when no enclosing handler-scope |
|
53 |
around the erronous code exists. |
|
54 |
(as the catch/through does). |
|
55 |
||
56 |
||
57 |
[see also:] |
|
58 |
GenericException |
|
59 |
(``Exception handling and signals'': programming/exceptions.html) |
|
4528 | 60 |
" |
61 |
||
62 |
||
4554 | 63 |
! |
64 |
||
65 |
examples |
|
66 |
" |
|
67 |
The emergencyHandler stuff is very useful, to prevent endUser applications |
|
68 |
from entering the debugger. |
|
69 |
||
70 |
Some commonly used (useful) emergency handlers are provided in the |
|
71 |
'useful handlers' section; try them to learn more |
|
72 |
(especially, the mailingHandler is fun). |
|
73 |
||
74 |
Of course, these are only examples - you may define your own handler |
|
75 |
block and pass it to the #emergencyHandler: method. |
|
76 |
||
77 |
BTW: the Launchers 'source & debugger' settings menu allows you |
|
78 |
to install either a default or the notifying handler. |
|
79 |
||
80 |
||
81 |
A handler which shows a box, then aborts - (no more debuggers): |
|
82 |
[exBegin] |
|
83 |
NoHandlerError emergencyHandler:(NoHandlerError abortingEmergencyHandler) |
|
84 |
[exEnd] |
|
85 |
||
86 |
||
87 |
A handler which aborts - (no box, no debugger): |
|
88 |
[exBegin] |
|
89 |
NoHandlerError emergencyHandler:[:ex | AbortSignal raise] |
|
90 |
[exEnd] |
|
91 |
||
92 |
||
93 |
try some exception (for demonstration, in some other process): |
|
94 |
[exBegin] |
|
95 |
[ |
|
96 |
#(1 2 3) at:4 |
|
97 |
] fork. |
|
98 |
[exEnd] |
|
99 |
||
100 |
cleanup (switch back to the regular handler, which enters the debugger): |
|
101 |
[exBegin] |
|
102 |
NoHandlerError emergencyHandler:nil |
|
103 |
[exEnd] |
|
104 |
||
105 |
||
106 |
A handler which shows a warnBox and asks for debugging: |
|
107 |
[exBegin] |
|
108 |
NoHandlerError emergencyHandler:(NoHandlerError notifyingEmergencyHandler) |
|
109 |
[exEnd] |
|
110 |
||
111 |
||
112 |
||
113 |
A handler which dumps information to a file (watch the file 'errorTrace.stx'): |
|
114 |
[exBegin] |
|
115 |
NoHandlerError emergencyHandler:(NoHandlerError dumpingEmergencyHandler) |
|
116 |
[exEnd] |
|
117 |
||
118 |
||
119 |
||
120 |
A handler which sends you mail: |
|
121 |
[exBegin] |
|
122 |
NoHandlerError emergencyHandler:(NoHandlerError mailingEmergencyHandler) |
|
123 |
[exEnd] |
|
124 |
" |
|
125 |
||
4528 | 126 |
! ! |
127 |
||
128 |
!NoHandlerError class methodsFor:'initialization'! |
|
129 |
||
130 |
initialize |
|
131 |
||
132 |
NotifierString := 'unhandled exception'. |
|
133 |
||
134 |
" |
|
135 |
self initialize |
|
136 |
" |
|
137 |
||
138 |
||
139 |
! ! |
|
140 |
||
141 |
!NoHandlerError class methodsFor:'emergency handlers'! |
|
142 |
||
143 |
emergencyHandler |
|
144 |
"return the handler used for unhandled exceptions. |
|
145 |
||
146 |
If no EmergencyHandler has been set, a handler which enters the |
|
147 |
debugger is returned. |
|
148 |
The debugger is opened by asking the signal for a debug action, |
|
149 |
this allows to provide other debuggers in specialized (subclass-instances) |
|
150 |
of Signal (if that is ever needed)" |
|
151 |
||
152 |
" |
|
153 |
set it up, when called the first time |
|
154 |
" |
|
155 |
EmergencyHandler isNil ifTrue:[ |
|
156 |
EmergencyHandler := [:ex | |
|
157 |
" |
|
158 |
sending it to the signal allows per-signal specific |
|
159 |
debuggers to be implemented in the future |
|
160 |
(for example, segv in primitive code could show things |
|
161 |
on the C-level ..) |
|
162 |
" |
|
4586
22c84f7f9b85
return nil from raise if proceeded in the debugger
Claus Gittinger <cg@exept.de>
parents:
4561
diff
changeset
|
163 |
(ex signal) openDebuggerOnException:ex. |
22c84f7f9b85
return nil from raise if proceeded in the debugger
Claus Gittinger <cg@exept.de>
parents:
4561
diff
changeset
|
164 |
"/ if we arrive here, the debugger proceeded. |
22c84f7f9b85
return nil from raise if proceeded in the debugger
Claus Gittinger <cg@exept.de>
parents:
4561
diff
changeset
|
165 |
"/ the value below is the exceptions value ... |
22c84f7f9b85
return nil from raise if proceeded in the debugger
Claus Gittinger <cg@exept.de>
parents:
4561
diff
changeset
|
166 |
nil |
4528 | 167 |
] |
168 |
]. |
|
169 |
||
170 |
^ EmergencyHandler |
|
171 |
||
172 |
||
173 |
! |
|
174 |
||
175 |
emergencyHandler:aOneArgBlock |
|
176 |
"set the handler used for unhandled exceptions. |
|
177 |
The default (a nil-handler) leads to a debugger to be shown." |
|
178 |
||
179 |
EmergencyHandler := aOneArgBlock |
|
180 |
||
181 |
"ST-80 behavior of first showing a notifier: |
|
182 |
(I prefer to get right into the debugger, though) |
|
183 |
||
184 |
Exception |
|
185 |
emergencyHandler: |
|
186 |
[:ex | self errorNotify:ex errorString ] |
|
187 |
" |
|
188 |
||
189 |
"ST-X behavior of going right into the debugger: |
|
190 |
||
191 |
Exception |
|
192 |
emergencyHandler:nil |
|
193 |
" |
|
194 |
||
195 |
"automatically aborting current operation, on error: |
|
196 |
(may be useful for end-user apps; make certain, |
|
197 |
you have abortSignal handlers at appropriate places) |
|
198 |
||
199 |
Exception |
|
200 |
emergencyHandler: |
|
201 |
[:ex | Object abortSignal raise. ex return. ] |
|
202 |
" |
|
203 |
||
204 |
"finally, traditional language system behavior; dump core ;-) |
|
205 |
||
206 |
Exception |
|
207 |
emergencyHandler: |
|
208 |
[:ex | Smalltalk exitWithCoreDump. ] |
|
209 |
" |
|
210 |
||
211 |
"Modified: 15.1.1997 / 20:49:06 / cg" |
|
212 |
||
213 |
! ! |
|
214 |
||
215 |
!NoHandlerError methodsFor:'default actions'! |
|
216 |
||
217 |
defaultAction |
|
218 |
"This action is performed, if nobody handles the NoHandlerError. |
|
219 |
Look for either a per-process emergencyHandlerBlock |
|
220 |
or the global emergencyHandler (from Exception) ..." |
|
221 |
||
222 |
|block| |
|
223 |
||
224 |
Processor notNil ifTrue:[ |
|
225 |
"care for signal during startup (Processor not yet created)" |
|
226 |
block := Processor activeProcess emergencySignalHandler. |
|
227 |
]. |
|
228 |
block isNil ifTrue:[ |
|
229 |
block := self class emergencyHandler. |
|
230 |
block isNil ifTrue:[ |
|
231 |
"care for error during startup (Exception not yet initialized)" |
|
4539
7064506e8285
debugger entry protocol changed;
Claus Gittinger <cg@exept.de>
parents:
4528
diff
changeset
|
232 |
^ MiniDebugger |
7064506e8285
debugger entry protocol changed;
Claus Gittinger <cg@exept.de>
parents:
4528
diff
changeset
|
233 |
enterWithMessage:self errorString |
7064506e8285
debugger entry protocol changed;
Claus Gittinger <cg@exept.de>
parents:
4528
diff
changeset
|
234 |
mayProceed:self mayProceed |
4528 | 235 |
]. |
236 |
]. |
|
237 |
||
4586
22c84f7f9b85
return nil from raise if proceeded in the debugger
Claus Gittinger <cg@exept.de>
parents:
4561
diff
changeset
|
238 |
^ block value:self |
4528 | 239 |
|
4561 | 240 |
! |
241 |
||
242 |
noHandler |
|
243 |
"redefined to avoid recursive invocations" |
|
244 |
||
245 |
^ self |
|
4528 | 246 |
! ! |
247 |
||
4539
7064506e8285
debugger entry protocol changed;
Claus Gittinger <cg@exept.de>
parents:
4528
diff
changeset
|
248 |
!NoHandlerError methodsFor:'queries'! |
7064506e8285
debugger entry protocol changed;
Claus Gittinger <cg@exept.de>
parents:
4528
diff
changeset
|
249 |
|
7064506e8285
debugger entry protocol changed;
Claus Gittinger <cg@exept.de>
parents:
4528
diff
changeset
|
250 |
mayProceed |
7064506e8285
debugger entry protocol changed;
Claus Gittinger <cg@exept.de>
parents:
4528
diff
changeset
|
251 |
"return true, if the exception handler is allowed to proceed |
7064506e8285
debugger entry protocol changed;
Claus Gittinger <cg@exept.de>
parents:
4528
diff
changeset
|
252 |
the execution where the exception occured." |
7064506e8285
debugger entry protocol changed;
Claus Gittinger <cg@exept.de>
parents:
4528
diff
changeset
|
253 |
|
7064506e8285
debugger entry protocol changed;
Claus Gittinger <cg@exept.de>
parents:
4528
diff
changeset
|
254 |
parameter isNil ifTrue:[^ true]. |
7064506e8285
debugger entry protocol changed;
Claus Gittinger <cg@exept.de>
parents:
4528
diff
changeset
|
255 |
^ parameter mayProceed |
7064506e8285
debugger entry protocol changed;
Claus Gittinger <cg@exept.de>
parents:
4528
diff
changeset
|
256 |
|
7064506e8285
debugger entry protocol changed;
Claus Gittinger <cg@exept.de>
parents:
4528
diff
changeset
|
257 |
|
7064506e8285
debugger entry protocol changed;
Claus Gittinger <cg@exept.de>
parents:
4528
diff
changeset
|
258 |
! ! |
7064506e8285
debugger entry protocol changed;
Claus Gittinger <cg@exept.de>
parents:
4528
diff
changeset
|
259 |
|
4528 | 260 |
!NoHandlerError class methodsFor:'documentation'! |
261 |
||
262 |
version |
|
4937 | 263 |
^ '$Header: /cvs/stx/stx/libbasic/NoHandlerError.st,v 1.6 1999-10-25 15:10:55 cg Exp $' |
4528 | 264 |
! ! |
265 |
NoHandlerError initialize! |