FirebirdSQL logo

RDB$ERROR()

Returns PSQL error information inside a WHEN …​ DO block

Available in

PSQL

Result type

Varies (see table below)

Syntax
RDB$ERROR (<context>)

<context> ::=
  GDSCODE | SQLCODE | SQLSTATE | EXCEPTION | MESSAGE
Table 1. Contexts
Context Result type Description

GDSCODE

INTEGER

Firebird error code, see also GDSCODE

SQLCODE

INTEGER

(deprecated) SQL code, see also SQLCODE

SQLSTATE

CHAR(5) CHARACTER SET ASCII

SQLstate, see also SQLSTATE

EXCEPTION

VARCHAR(63) CHARACTER SET UTF8

Name of the active user-defined exception or NULL if the active exception is a system exception

MESSAGE

VARCHAR(1024) CHARACTER SET UTF8

Message text of the active exception

RDB$ERROR returns data of the specified context about the active PSQL exception.Its scope is confined to exception-handling blocks in PSQL (WHEN …​ DO).Outside the exception handling blocks, RDB$ERROR always returns NULL.This function cannot be called from DSQL.

Example of RDB$ERROR

BEGIN
  ...
WHEN ANY DO
  EXECUTE PROCEDURE P_LOG_EXCEPTION(RDB$ERROR(MESSAGE));
END