Navigation: Programming Cookbook > Database Connectivity >
ODBC Error handling
All of the Database Connection operations that result in calls to the underlying ODBC driver are checked for errors when they return. If an error occurs during an a ODBC call then a Smalltalk DBError exception is raised. The default outcome of a DBError signal is a walkback that indicates that the exception has not been handled. The walkback includes a textual description of the error as part of its caption. However, since the ODBC error messages tend to be quite verbose, it is not always possible to read the entire message from the walkback window. In these situations just enter the debugger by pressing Debug. This will allow you to read the message more easily.
Often, you will want to intercept DBError exceptions to handle them in more application specific way. You can do this by a enclosing the original Database Connection calls in a block and using #on:do: to trap the error. Here's an example that traps an open connection error and reports the message to the Transcript rather than bringing up a walkback.
[ (DBConnection new) dsn: 'NonExistent'; connect. ] on: DBError do: [:e |
Transcript show: e details errors first msg; cr ].