Unable to use ESQLDatabaseError lazarus / 16-Databases ---------------------------------------------------------------------- talorigomat · 2017-10-13 16:28 I'm trying to use ESQLDatabaseError to catch the error code and message from a Firebird database but am having no joy.  I'm using the following code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     try    dmMain.qrySite.ApplyUpdates();      dmMain.trnMain.Commit;     except      on E:ESQLDatabaseError do      begin        ShowMessageFmt('ErrorCode: %d; Message: %s', [E.ErrorCode, E.Message]);      end; if I use DatabaseError exception as Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     try    dmMain.qrySite.ApplyUpdates();      dmMain.trnMain.Commit;      on E:EDatabaseError  do      begin        ShowMessage(E.Message);      end;    end; Then I can catch the exceptions, however this form doesn't give me the databases sql error code. I'm using the SQLDB components to access the database and I'm using Lazarus 1.8.0 RC4 with MS Windows 10. ---------------------------------------------------------------------- balazsszekely · 2017-10-14 05:16 What is the actual exception in your second code? ---------------------------------------------------------------------- talorigomat · 2017-10-17 13:59 Apologies.  Been away for a bit.  It is Violation of PRIMARY or UNIQUE KEY constraint "UK_STENME" ON TABLE "SITE" ---------------------------------------------------------------------- rvk · 2017-10-17 14:06 Your second code is invalid because "on E: Exception" always needs to be in an except-block. Try this and tell us what classname you get. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i try  dmMain.qrySite.ApplyUpdates();  dmMain.trnMain.Commit;except  on E: Exception do    Showmessage('Exceptionclass = ' + E.ClassName + ' / ' + E.Message);end; You can use the text of ClassName as the actual exceptionclass. And if that class is really an SQLException you can use E.ErrorCode after you change "on E: Exception" to "on E: Excptionclassname". ---------------------------------------------------------------------- talorigomat · 2017-10-17 15:40 Hi Rvk thanks for pointing that out.  I accidentally deleted that before posting.  Using the code you supplied the class name returned is "EUpdateError". ---------------------------------------------------------------------- talorigomat · 2017-10-17 17:05 I've attached a simple project.  The place of interest is on the btnSaveClick method on the Site form.  To illustrate I've included  on E:ESQLDatabaseError, on E:EDatabaseError and on E: Exception in the exception block. Commenting out E:EDatabaseError and E: Exception blocks exceptions go through to the default exception handler bypassing the ESQLDatabaseError handler.  uncomment either E:EDatabaseError and E: Exception then the exception is handled by the one that is uncommented.  ESQLDatabaseError isn't catching anything. ---------------------------------------------------------------------- rvk · 2017-10-17 17:11 Quote from: talorigomat on October 17, 2017, 05:40:37 pmUsing the code you supplied the class name returned is "EUpdateError". So... don't use ESQLDatabaseError but use EUpdateError. It also has a ErrorCode property. ESQLDatabaseError isn't catching anything because that's not the exception that occurs. ---------------------------------------------------------------------- talorigomat · 2017-10-19 16:32 Thanks for the helping with this rvk.  Now I understand this better.