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