Subject Re: logging exception message text in stored procedures
Author tommyjky
--- In firebird-support@yahoogroups.com, Helen Borrie <helebor@...> wrote:
>
> At 09:52 AM 14/02/2006, tommyjky wrote:
> >I have a store procedure in which I want to to write exeptions to a
> >log table. When I get an error, I want to call a stored procedure and
> >send the text of the error message and write it to a table. I don't
> >know the field that the error text is stored in. Can someone please
> >tell me the name of the field where I can get the error message text.
>
> The short answer is that there isn't a "field". Exceptions exist on
> the server as numbers. When they are returned to a client, you get
> those numbers, along with the associated text for each number, in an
> array that is populated at the interface, i.e. after the exception
> has left the server, from firebird.msg.
>
> The long answer is that, if you want to have text available on the
> server to explain each exception, you'll need to create custom
> exceptions for each one you might ever want to log. You can query
> the system table RDB$EXCEPTIONS then by passing the identifier of
> your custom exception as a string and getting back the text you
> defined for that exception; or, in Fb 1.5 and higher, you can
> override the defined text and store that in your log instead.
>
> Something you'll have to watch is, if you are writing your log
> records to an ordinary table, rather than an external table, the log
> records will disappear along with everything else if the transaction
> gets rolled back. (Log records written to an external table will
survive.)
>
> ./heLen

>Ok, but how do I get the exception name? I know how to get SQLCODE
and/or GDSCODE, but you are saying that I need the exception name so
that I can query the RDB$EXCEPTIONS TABLE to get the RDB$MESSAGE,
right? When an exception occurs, is there a field or something that I
can use to get the name of the exception so that I can query the
RDB$EXCEPTIONS table to get the RDB$MESSAGE?