TZConnection Exception Handling

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
Antz
Fresh Boarder
Fresh Boarder
Posts: 14
Joined: 06.12.2006, 14:01

TZConnection Exception Handling

Post 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
pioter
Fresh Boarder
Fresh Boarder
Posts: 1
Joined: 07.08.2007, 10:30

Post 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.
Antz
Fresh Boarder
Fresh Boarder
Posts: 14
Joined: 06.12.2006, 14:01

Post by Antz »

Thank you. Will try that and let you know the results. Again, many thanks. :)
Post Reply