Firebird Documentation IndexFirebird 2.5 Language Ref. UpdatePSQL statements → EXCEPTION
Firebird Home Firebird Home Prev: DECLAREFirebird Documentation IndexUp: PSQL statementsNext: EXECUTE PROCEDURE

EXCEPTION

Rethrowing a caught exception
Providing a custom error message

Available in: PSQL

Changed in: 1.5

Description: The EXCEPTION syntax has been extended so that the user can

  1. Rethrow a caught exception or error.

  2. Provide a custom message when throwing a user-defined exception.

Syntax: 

EXCEPTION [<exception-name> [custom-message]]

<exception-name>  ::=  A previously defined exception name

Rethrowing a caught exception

Within the exception handling block only, you can rethrow the caught exception or error by giving the EXCEPTION command without any arguments. Outside such blocks, this “bare” command has no effect.

Example: 

when any do
begin
  insert into error_log (...) values (sqlcode, ...);
  exception;
end

This example first logs some information about the exception or error, and then rethrows it.

Providing a custom error message

Firebird 1.5 and up allow you to override an exception's default error message by supplying an alternative one when throwing the exception.

Examples: 

exception ex_data_error 'You just lost some valuable data';
exception ex_bad_type 'Wrong type for record with id ' || new.id;

Note

Starting at version 2.0, the maximum message length is 1021 instead of 78 characters.

Prev: DECLAREFirebird Documentation IndexUp: PSQL statementsNext: EXECUTE PROCEDURE
Firebird Documentation IndexFirebird 2.5 Language Ref. UpdatePSQL statements → EXCEPTION