catching post errors not using events

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ads42
Posts: 36
Joined: Tue 08 Jan 2013 14:13

catching post errors not using events

Post by ads42 » Tue 05 Feb 2013 10:52

Hi,
I have some web services that post datas to tables.
I have to catch table post errors in the same function not using the onPostError event.
I will use something like this :

Code: Select all

// Go into edit mode
  MyDataset.Edit;
  try
    // Set the field(s)
    // .. you can add all the fields here ...
    MyDatset['Somefield'] := SomeValue;

    // attempt to post the data
    MyDataset.Post;
  except
    // something has gone wrong, cancel the edit
    MyDataset.Cancel;
  end;
How can I get the error message with a try except ?
Thanks

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: catching post errors not using events

Post by DemetrionQ » Wed 06 Feb 2013 16:53

Hello.

To retrieve error data in the 'try except' block, use the instruction 'On E:Exception Do '. For example:

Code: Select all

try
 //...
except
  On E:Exception Do
    begin
      //...
      ShowMessage(E.Message);
    end;
end;

ads42
Posts: 36
Joined: Tue 08 Jan 2013 14:13

Re: catching post errors not using events

Post by ads42 » Wed 06 Feb 2013 19:15

thanks

Post Reply