Programming Guide : Working with a Database : Handling Database Errors : How You Can Use the ErrorNumber and DBMSError Attributes
 
Share this page          
How You Can Use the ErrorNumber and DBMSError Attributes
Every database session has access to errors that occur during the execution of a database statement by accessing the values in the ErrorNumber and DBMSError attributes.
ErrorNumber
Contains the generic error number associated with the error
DBMSError
Contains the database-specific error number associated with the error
A generic error represents a class of error, and the database-specific number identifies a specific error associated with a specific DBMS within that class.
The values in ErrorNumber and DBMSError reflect the status of the last database statement that the application attempted to execute in the current session. If the statement was executed, each of these attributes is set to zero. If the statement did not execute because of an error, then these attributes contain the appropriate error numbers.
These attributes are also set when an error occurs setting the DBHandle attribute of a bitmap or string object.
As an example, the 4GL procedure dbms_error_message demonstrates one way to use these variables. This procedure displays an error message to the user when a DBMS error occurs:
procedure dbms_error_message () =
begin
    if CurFrame.DBSession.ErrorNumber != 0 then
        return 'Error code is' +
            varchar(CurFrame.DBSession.ErrorNumber)
        +'. DBMS specific error number is' +
            varchar(CurFrame.DBSession.DBMSError) +
            '.';
    else
        return '';
    endif;
end;