Handling error objects
VA Smalltalk provides a default error routine that puts up a debugger window whenever an error is encountered. You can override this default temporarily or permanently by providing your own response to the error.
The following examples illustrate how to do the following:
• Temporarily override the default error routine
• Permanently override the default error routine
• Restore the default error routine
Note:
To ensure that database processing completes, return an error object or some other appropriate object. Do not return directly from the error block.
Temporarily overriding the default error routine
This sample code temporarily causes an error to print in the Transcript window instead of in a message box.
Before you can use this sample code, you need to define a connection specification and establish a database connection.
To use this sample code, follow these steps:
1. Evaluate the code using the Inspect command.
2. Look at the contents of the System Transcript to see the error message generated.
"Temporarily overrides default error routine"
| querySpec result resultCollection connection err|
resultCollection := OrderedCollection new.
connection := AbtDbmSystem activeDatabaseConnectionWithAlias: 'SampleConSpec'.
querySpec := (AbtQuerySpec new)
statement: 'SELECT * FROM BLAH'.
result :=
connection
resultTableFromQuerySpec: querySpec
ifError: [ :error |
Transcript cr; show: (error errorText printString).
error
].
^result.
Permanently overriding the default error routine
If you want to override the error routine permanently for all database messages displayed by VA Smalltalk, send the errorBlock: method to the current active connection.
This example assumes that you have an active connection.
To use this sample code, evaluate it using the Inspect command.
"Permanently overrides error routine"
AbtDbmSystem activeDatabaseMgr errorBlock: [
:error | Transcript show: (error errorText printString).].
Restoring the default error routine
To reset the error routine to the default, supply a value of NIL.
This example assumes that you have an active connection.
To use this sample code, evaluate it using the Execute command.
"Resets error routine to default"
AbtDbmSystem activeDatabaseMgr errorBlock: nil.
Last modified date: 01/29/2015