Try-Except vs OnError for MyConnection and MyQuery

Try-Except vs OnError for MyConnection and MyQuery

Postby 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!!!
TheLion
 
Posts: 39
Joined: Thu 25 Nov 2004 11:28
Location: Copenhagen/Denmark

Postby 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.
Ikar
 
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Postby 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
TheLion
 
Posts: 39
Joined: Thu 25 Nov 2004 11:28
Location: Copenhagen/Denmark

Postby 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;
Ikar
 
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Postby 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 :-)
TheLion
 
Posts: 39
Joined: Thu 25 Nov 2004 11:28
Location: Copenhagen/Denmark


Return to MySQL Data Access Components