Page 1 of 1

When use TMyConnection.OnError?

Posted: Fri 06 Nov 2015 18:59
by davidmarcus
I'm using TMyConnection and TMyScript to communicate with a MySQL
server. For TMyScript, I do

Code: Select all

Action := eaFail;
in the TMyScript.OnError event. I then do

Code: Select all

try
   ...
except
   on E: EDAError do
      ...
end;
and log the errors. I've looked at the docs (and the source), but I'm
not sure if I should be using a TMyConnection.OnError event. The docs
say that setting Fail to false will prevent a dialog and raise EAbort.
I would like to prevent any dialogs; I want to catch the exceptions
and log them. Should I set Fail to false? If so, do I need to catch
errors other than EDAError?

MyDAC Professional 8.6.19, Delphi 10 Seattle.

Re: When use TMyConnection.OnError?

Posted: Mon 09 Nov 2015 16:35
by ViktorV
You can use the TMyConnection.OnError event to process all the exceptions that occur when working with databases. When any error occurs, this event is triggered. To handle and log an exception that occurs when working with the database, you can just use properties and methods of the EDAError class. To avoid showing error messages, you should set the Fail parameter in the TMyConnection.OnError event handler to False.

Re: When use TMyConnection.OnError?

Posted: Mon 09 Nov 2015 20:46
by davidmarcus
Thank you. So, I can log the errors in TMyConnection.OnError and set Fail to false. I still need a try..except to catch the EDAError's, but it doesn't have to do anything. Correct?

Re: When use TMyConnection.OnError?

Posted: Tue 10 Nov 2015 15:01
by ViktorV
Yes, you can use the TMyConnection.OnError event handler for logging by setting the Fail parameter to False. But in this case you won't be able to use a try...except block for interception of EDAError errors. To catch EDAErrors using try...except, you should set the Fail parameter of TMyConnection.OnError to True and the Action parameter of TMyScript.OnError - to eaFail.

Re: When use TMyConnection.OnError?

Posted: Tue 10 Nov 2015 15:12
by davidmarcus
Got it. Thank you.

Re: When use TMyConnection.OnError?

Posted: Tue 10 Nov 2015 15:25
by ViktorV
If you have any questions during using our products, please don't hesitate to contact us - and we will try to help you solve them.