FirebirdSQL logo

This section describes how to create, modify and delete custom exceptions for use in error handlers in PSQL modules.

CREATE EXCEPTION

Creates a custom exception for use in PSQL modules

Available in

DSQL, ESQL

Syntax
CREATE EXCEPTION exception_name '<message>'

<message> ::= <message-part> [<message-part> ...]

<message-part> ::=
    <text>
  | @<slot>

<slot> ::= one of 1..9
Table 1. CREATE EXCEPTION Statement Parameters
Parameter Description

exception_name

Exception name.The maximum length is 63 characters

message

Default error message.The maximum length is 1,021 characters

text

Text of any character

slot

Slot number of a parameter.Numbering starts at 1.Maximum slot number is 9.

The statement CREATE EXCEPTION creates a new exception for use in PSQL modules.If an exception with the same name exists, the statement will raise an error.

The exception name is an identifier, see Identifiers for more information.

The default message is stored in character set NONE, i.e. in characters of any single-byte character set.The text can be overridden in the PSQL code when the exception is thrown.

The error message may contain “parameter slots” that can be filled when raising the exception.

Warning

If the message contains a parameter slot number that is greater than 9, the second and subsequent digits will be treated as literal text.For example @10 will be interpreted as slot 1 followed by a literal ‘0’.

Note

Custom exceptions are stored in the system table RDB$EXCEPTIONS.

Who Can Create an Exception

The CREATE EXCEPTION statement can be executed by:

The user executing the CREATE EXCEPTION statement becomes the owner of the exception.

CREATE EXCEPTION Examples

Creating an exception named E_LARGE_VALUE
CREATE EXCEPTION E_LARGE_VALUE
  'The value is out of range';
Creating a parameterized exception E_INVALID_VALUE
CREATE EXCEPTION E_INVALID_VALUE
  'Invalid value @1 for field @2';