Recent

Author Topic: Error Firebird in Lazarus  (Read 842 times)

calm_sea

  • New Member
  • *
  • Posts: 31
Error Firebird in Lazarus
« on: February 23, 2023, 12:03:39 pm »
Hi everyone. I can't find a way to catch firebird errors from lazarus. With IBEventMonitor I can acquire the errorcode but I can't get the string of the error.

rvk

  • Hero Member
  • *****
  • Posts: 5193
Re: Error Firebird in Lazarus
« Reply #1 on: February 23, 2023, 12:16:09 pm »
Hi everyone. I can't find a way to catch firebird errors from lazarus. With IBEventMonitor I can acquire the errorcode but I can't get the string of the error.
Can't you just use the try/except handling?

It depends on the components used but if you use IBX.

With the normal Exception:
Code: Pascal  [Select][+][-]
  1. try
  2.   // do your thing with SQL
  3. except
  4.   on E: Exception do
  5.   begin
  6.     // your generic message is in E.Message
  7.     if (E is EIBInterBaseError) then
  8.     begin
  9.       // your errorcode is in EIBInterBaseError(E).IBErrorCode
  10.       // and sqlcode is in EIBInterBaseError(E).SQLCode
  11.     end;
  12.   end;
  13. end;

If you only need to catch the EIBInterBaseError then you can do this:
Code: Pascal  [Select][+][-]
  1. try
  2.   // do your thing with SQL
  3. except
  4.   on E: EIBInterBaseError do
  5.   begin
  6.     // your errorcode is in EIBInterBaseError(E).IBErrorCode
  7.     // and sqlcode is in EIBInterBaseError(E).SQLCode
  8.   end;
  9. end;

Other exceptions will pass through to the caller function.
« Last Edit: February 23, 2023, 12:19:05 pm by rvk »

calm_sea

  • New Member
  • *
  • Posts: 31
Re: Error Firebird in Lazarus
« Reply #2 on: February 23, 2023, 02:54:14 pm »
Yes, thanks. I was wondering if it's possible to centralize error handling across the whole db, not at the level of each specific query. I had thought that with IBEventManager it was possible, but I can't do it

rvk

  • Hero Member
  • *****
  • Posts: 5193
Re: Error Firebird in Lazarus
« Reply #3 on: February 23, 2023, 05:04:28 pm »
Yes, thanks. I was wondering if it's possible to centralize error handling across the whole db, not at the level of each specific query. I had thought that with IBEventManager it was possible, but I can't do it
No, not that I'm aware of.

It wouldn't make sense to me because every part of your program (and DB handling) could require it's own special handling.
If that's not the case you can just let the exception happen and handle it with the Application.OnException (you can write your own generic exception handler).

calm_sea

  • New Member
  • *
  • Posts: 31
Re: Error Firebird in Lazarus
« Reply #4 on: March 20, 2023, 01:44:25 pm »
OK thank you! One last thing. How can I get firebird error messages in Italian? Is there a firebird.msg file in Italian?

rvk

  • Hero Member
  • *****
  • Posts: 5193
Re: Error Firebird in Lazarus
« Reply #5 on: March 20, 2023, 02:49:58 pm »
Is there a firebird.msg file in Italian?
Not that I know of.
In the source there is a directory \src\msgs where the firebird.msg is build.
There are translations in German en French. Not any other.
(Maybe some third party has translated them once.)

You could also make your own translation. But you can also catch exceptions program wide and translate them then.

Besides, for most messages I would prefer the original English ones.
Otherwise it's a lot harder to search the internet for solutions when you get those in another language.

Only for the most common error codes (like DB not found and Record liked and some others) I provide translations.

Edit: O, and IB EXpert had a tool for directly translating the Firebird.msg.
http://www.ibexpert.net/ibe/index.php?n=Doc.LocalizeIBMessages

dogriz

  • Full Member
  • ***
  • Posts: 126
Re: Error Firebird in Lazarus
« Reply #6 on: March 21, 2023, 02:21:03 pm »
You can create your own exceptions in any language you like in Firebird with CREATE EXCEPTION ...
Check employee demo database as an example.
FPC 3.2.2
Lazarus 2.2.4
Debian x86_64, arm

 

TinyPortal © 2005-2018