Try-Except vs OnError for MyConnection and MyQuery

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
TheLion
Posts: 39
Joined: Thu 25 Nov 2004 11:28
Location: Copenhagen/Denmark

Try-Except vs OnError for MyConnection and MyQuery

Post by TheLion » Fri 04 Mar 2005 14:30

Hi :-)

Running MyDAC v3.50.0.16 with Delphi 5 on MySQL 4.0.23-classic

I have a problem with getting a error message out of my program, for a simple Select statement that fails.

None of the OnError events cath the fault. It does get trapped into the Except-End loop. Is there any why I can get an error message from within that loop?

Btw. if I copy the Select statement from my errorlog and paste it in the query browser it works!!!

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Sat 05 Mar 2005 14:01

OnError determines type of the exception that will be generated on error (EMyError or EAbort). In both cases to handle errors in the queries you need try..except block.

> Btw. if I copy the Select statement from my errorlog and paste it in the query
> browser it works!!!

Please send us complete small sample to demonstrate it and include script to create server objects.

TheLion
Posts: 39
Joined: Thu 25 Nov 2004 11:28
Location: Copenhagen/Denmark

Post by TheLion » Sat 05 Mar 2005 14:32

Hi :-)

I have a Try Except block. But how do I get an error txt string from inside this block. I need that to save it to my Log, so I can see what goes wrong.

In the different OnError... events I have EDAError or EDatabaseError and can get an error text message from that type. My Question is how do I get an error text from within the Try Except block.

My Main program works on 2 servers, but not on the 3th one. If I make a small sample program, that works on all 3 servers!!! I have to find out what is wrong. Normally any errors get trapped in an OnError... event for either MyConnection or MyQuery. But this one only get to the Except-End part of the Try Except block!!!

I use these onerror methods.

Code: Select all

MyQuery.Connection.OnError
MyQuery.OnDeleteError
MyQuery.OnEditError
MyQuery.OnPostError
MyQuery.OnUpdateError 

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Wed 09 Mar 2005 15:44

> how do I get an error text from within the Try Except block.

You should use the next construction:

Code: Select all

try
except
  on e: EMyError do begin
    ...
  end;
end;

TheLion
Posts: 39
Joined: Thu 25 Nov 2004 11:28
Location: Copenhagen/Denmark

Post by TheLion » Wed 09 Mar 2005 16:07

Hi :-)

Thats way to simple ;-) Why didn't I think of that!!!!

That will solve my problem :-)

Thank you :-)

Post Reply