There are cases when you might not want to receive a stack dump. VisualAge Smalltalk Server provides a method which allows you to ignore an error condition and perform your own exception routine. This method also allows you to produce a stack dump at your discretion.
The whenExceptionDo: method permits you to write a block of code that suspends normal processing for your own exception routine. In this block, you can choose to produce a stack dump and exit the application without returning to Smalltalk processing.
The method is used by specifying a block of code, which can be your application launch code, then a block of code that performs your exception routine. For example, the following doit method launches an application and, if that application fails, produces a stack dump and exits the image without allowing Smalltalk to regain control.
doit
| startUpClass dumperClass |
[MyClass run]
whenExceptionDo: [
startUpClass := System startUpClass.
(startUpClass respondsTo: #stackDumperClass)
ifTrue: [dumperClass := startUpClass stackDumperClass].
Transcript cr;
show: 'startUpClass=',startUpClass printString;
cr; flush.
Transcript cr;
show: 'dumperClass=',dumperClass printString;
cr; flush.
"Test for a dumper class before dumping the stack"
(dumperClass isNil)
ifFalse: [Transcript show: 'dumping Stack ...... '; cr; flush.
dumperClass dumpStack: 'This is the Stack Dump Message'].
Transcript show: 'explicit return to CICS prevents exception abend';
cr; flush.
System exit.
]
You can also use the method System exit:withObject: to exit with a user return code. If you are running under CICS, you must use CICS return exec to exit the image without allowing Smalltalk to regain control.