Page 1 of 1

TZConnection Exception Handling

Posted: 06.08.2007, 12:11
by Antz
I am trying to raise an exception when the database property of the connection is entered incorrectly. The application uses 2 databases, a test database and a production database. When the database name is entered incorrectly I get an error message (which is correct) but I want to customize the error message. The application throws the message with SQL Error -902 (also correct). My code is as follows:

[font=Courier New]conxApplication.Username := editUsername.Text;
conxApplication.Password := editPassword.Text;
conxApplication.Database := editDatabase.Text;
try
conxApplication.Connect
except on <?> do
begin
MessageDlg(‘You specified an incorrect database’,......);
editDatabase.SetFocus;
Exit;
end;
[/font]

The <?> in the exception part is what I do not know. What are the exceptions that the TZConnection component can throw? And on an exception, how can I address the specific error code that is thrown by the exception?

I am using ZEOSLIB 6.6.1 Beta, Delphi 7 and Firebird 2.0.1

Any help would be great,
Many thanks in advance.
Antz

Posted: 07.08.2007, 10:51
by pioter
you can catch an exception by:

Code: Select all

on E:Exception do
begin
MessageDlg(‘You specified an incorrect database. Error details: ’ + E.Message,......);
editDatabase.SetFocus;
Exit;
end;
or during execution in debug mode. In that case Delphi should inform you which exception class was thrown , unless you turn off this in options.

Posted: 07.08.2007, 11:17
by Antz
Thank you. Will try that and let you know the results. Again, many thanks. :)