[Solved] Where is EDatabaseError defined lazarus / 16-Databases ---------------------------------------------------------------------- dokhebi · 2012-12-11 21:09 Using Laz 1.0.4 & FPC 2.6.0 on WinXP. I want to catch an exception like this: Code: [Select]  try     MySQL51Connection1.Connected := True;   except     On E: EDatabaseError do       begin         ShowMessage('Could not connect to database');         Close;       end;   end; but I get the following message: Code: [Select]main.pas(53,11) Error: Identifier not found "EDatabaseError" main.pas(53,26) Error: class type expected, but got "" main.pas(69) Fatal: There were 2 errors compiling module, stopping Where is EDatabaseError defined?  Is there a package/unit I need to include to make it work? Thanks in advance. Edward Hooper ---------------------------------------------------------------------- BlueIcaro · 2012-12-11 21:39 It's on unit DB. More info: http://www.freepascal.org/docs- html/fcl/db/edatabaseerror.html /BlueIcaro ---------------------------------------------------------------------- dokhebi · 2012-12-11 22:00 I included unit DB so it compiles, but it's not catching the exception.  Is there a property in the application or the control that states I will handle all exceptions? ---------------------------------------------------------------------- Zoran · 2012-12-11 22:39 Quote from: dokhebi on December 11, 2012, 11:00:03 pmI included unit DB so it compiles, but it's not catching the exception.  Is there a property in the application or the control that states I will handle all exceptions? Perhaps the raised exception is not EDatabaseError? Try something like this: Code: [Select]  try     MySQL51Connection1.Connected := True;   except     on E: Exception do begin       if E is EDatabaseError then         ShowMessage('Could not connect to database')       else         ShowMessage('Raised Exception: ' + E.ClassName + LineEnding + 'with message:' + E.Message);     end;   end; ---------------------------------------------------------------------- BigChimp · 2012-12-12 06:57 You can also catch multiple exceptions like this (air code, typed in this post, not tested) - go from most specific exception to least specific: Code: [Select]  try     MySQL51Connection1.Connected := True;   except // you can also do on C: E... database specific error (e.g. defined in ibconnection, mssqlconnection etc depending on which db you use. These often give some more detailed error messages)     on D: EDatabaseError do begin         ShowMessage('Database error is raised.')     end;     on E: Exception do begin         ShowMessage('Raised Exception: ' + E.ClassName + LineEnding + 'with message:' + E.Message);     end;   end; ---------------------------------------------------------------------- dokhebi · 2012-12-12 19:04 I found out what was happening.  The Lazarus environment runs the debugger by default so it catches the exception first.  I would click on Break in the pop-up message and the program would pause.  When I click on Continue it lets the exception handler code do its thing.  When I run the compiled binary outside of Lazarus it behaves as expected. Thanks for the help. ---------------------------------------------------------------------- BlueIcaro · 2012-12-12 20:47 Quote from: dokhebi on December 12, 2012, 08:04:23 pmI found out what was happening.  The Lazarus environment runs the debugger by default so it catches the exception first.  I would click on Break in the pop- up message and the program would pause.  When I click on Continue it lets the exception handler code do its thing.  When I run the compiled binary outside of Lazarus it behaves as expected. Thanks for the help. That  is the correct way that debuger works in Lazarus, and as i remenber in the version of  Delphi that I used. /BlueIcaro