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
TZConnection Exception Handling
Moderators: gto, cipto_kh, EgonHugeist
you can catch an exception by:
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.
Code: Select all
on E:Exception do
begin
MessageDlg(‘You specified an incorrect database. Error details: ’ + E.Message,......);
editDatabase.SetFocus;
Exit;
end;