Today's Smalltalk 4 You looks at error handling for database development in VA Smalltalk. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:
You can also watch it on YouTube:
Today we'll look at setting (and unsetting) an error handler for database exceptions. In some cases, you may not want to catch all possible errors at the place they originate; you'll want a catchall handler specific to database issues. That turns out to be easy to set up in VA Smalltalk:
"set up an error handler for db work" AbtDbmSystem activeDatabaseMgr errorBlock: [:error | Transcript show: 'Whoops, that did not work out for us: ', error errorText printString; cr].
To illustrate, let's execute a query that won't work:
"try a query that should throw an error" resultCollection := OrderedCollection new. querySpec := (AbtQuerySpec new) statement: 'SELECT EMAIL FROM PEOPLE'. result := connection resultTableFromQuerySpec: querySpec. result do: [:eachRow | resultCollection add: (eachRow)]. ^resultCollection.
Instead of an error notifier, you get a message in the Transcript:
This can be useful when you are running a server system, and don't want a default notifier to pop up. Instead, you can log the error, and then have the system do something intelligent - quit, reset connections, whatever. If you want to reset to the default handling (for development, probably), just execute the same code with a nil argument:
"reset to default handling" AbtDbmSystem activeDatabaseMgr errorBlock: nil.
Now you'll see the default handling when you try that bad query:
Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.
[st4u153-iPhone.m4v ( Size: 4461165 )]