How to Handle EDatabaseError from MySQL? lazarus / 8-Other ---------------------------------------------------------------------- anderson5420 · 2008-05-31 17:48 OK, new to Lazarus, love it so far! I more or less duplicated the little program tryMySQL from the MYSQLDatabases article in the Wiki that uses the SQLdb components - WAY slick, so much better than where I left off from Delphi (Delphi 4, about 10 years ago, but it is like riding a bike!).  System is XP under Parallels 3 on a MacBook.  MySQL is version 5.0.  The compiiled program runs great until I try to open an invalid SQL command either by accident or on purpose.  Lazarus then goes into debugging mode with "Project raised an EDatabaseError."  This is not unexpected of course. In the MySQL command line tool, it just returns the nature of the error and lets you try again. So I am wondering how to handle this error and let the user try again in my faux tryMySQL program. Here is what I have in the code for the event handler for the button that opens the SQL command: Code: [Select] procedure TMainForm.ExecuteQueryButtonClick(Sender: TObject); begin   SQLQuery1.SQL.Text := CommandEdit.Text;   SQLQuery1.ParseSQL := false;   SQLQuery1.ReadOnly := true;   try     SQLQuery1.Open;   except      ShowString('Unable to execute SQL command');    end; end; I thought maybe the try...except would handle the error, but evidently it only handles Lazarus errors, not the MySQL errors. Have Googled this, tried the Search here, am coming up empty.  Anyway, would appreciate it if somebody could help me figure out how to handle the EDatabaseError so that the user can just go on and try again. Thanks! Pat Anderson ---------------------------------------------------------------------- anderson5420 · 2008-06-01 16:01 Guess I'm talking to myself!  Did a bit more searching on the Wiki and came up with this. Ought to work but doesn't, still gives EDatabaseError message and goes into debbugging mode.  Why doesn't this work? Code: [Select] procedure TMainForm.ExecuteQueryButtonClick(Sender: TObject); begin      SQLQuery1.SQL.Text := CommandEdit.Text;      try         SQLQuery1.Open;      except            on E : EDatabaseError do               ShowString('DB ERROR:' + ' ' + E.ClassName + ' ' + E.Message);            on E : Exception do               ShowString('ERROR:' + ' ' + E.ClassName + ' ' + E.Message);      end; end; ---------------------------------------------------------------------- anderson5420 · 2008-06-02 12:24 Well, interesting thing...I did a build with the error handling on the SQLQuery1.Open as above. The program handles the error fine outside the IDE, it just logs the error and lets the user keep going, but inside the IDE the error causes Lazarus to suspend normal execution of the program and go into the debugger. Is this behavior a bug in the IDE?  I would think that if a program actually is handing an error properly, the IDE should not suspend the program. I wasted a fair amount of time trying to research why code that should work did not seem to be working, when all along apparently it was working fine... ---------------------------------------------------------------------- Leledumbo · 2008-06-03 06:22 Another debugger problem... try replacing the debugger (e.g. download your own).