How to Trap Database Errors

Hi folks,

I'm using Delphi 3 C/S and SQL Server 6.5 to write an application.  Now I
added a screen to my application which should enable the user to change
his/her password.  The screen simply calls MS SQL Server's sp_password Stored
Procedure (from the Master database).

The procedure works propperly, but I can't seem to trap errors and send
information back to the user about the error message.

In my form the following code is called when the user presses the OK button :

     with dmSQLServerSpecific.sp_password do
          ParamByName('User').AsString := edtUserName.Text;
          ParamByName('OldPass').AsString := edtPassword.Text;
          ParamByName('NewPass').AsString := edtNewPasword1.Text;
                lblmessage.caption := 'Password has been changed';
                lblmessage.caption := 'Unable to change password';

What I would like to do now is trap the error generated by the database.  For
example if the user entered the old password incorrectly (when the program is
run from withing Delphi), i get a message like : Project raised exception
class EDBEngineError with message : 'Old (current) password incorrect for
user --- password not changed' ...

Now I would like to trap this error and the message so that I can show this
errormessage to the user (in the lblmessage label).

How should I do this ? Anyone in here who can help me ?

If possible, please also send a copy of your response to : (remove NOSPAM) so that I'm sure I read it.

Thanks a lot in advance.

-----------== Posted via Deja News, The Discussion Network ==----------       Search, Read, Discuss, or Start Your Own