Page 1 of 1

catching post errors not using events

Posted: Tue 05 Feb 2013 10:52
by ads42
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

Re: catching post errors not using events

Posted: Wed 06 Feb 2013 16:53
by DemetrionQ
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;

Re: catching post errors not using events

Posted: Wed 06 Feb 2013 19:15
by ads42
thanks