. .


ST 4U 153: Handling Database Framework Errors in VA Smalltalk

November 2, 2011 7:55:28.136

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:

Database Errors.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

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)
result := connection resultTableFromQuerySpec: querySpec.
result do: [:eachRow | resultCollection add: (eachRow)].

Instead of an error notifier, you get a message in the Transcript:

Error Handling

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:

Default Error Handling

Default Error Handling

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.

Technorati Tags: , ,

[st4u153-iPhone.m4v ( Size: 4461165 )]

posted by James Robertson

 Share Tweet This