Firebird Documentation IndexFirebird 1.5 Language Ref. UpdatePSQL statements → EXCEPTION
Firebird Home Firebird Home Prev: DECLARE [VARIABLE] with initializationFirebird Documentation IndexUp: PSQL statementsNext: EXECUTE PROCEDURE

EXCEPTION

Table of Contents

Rethrowing a caught exception
Providing a custom error message

Tip

Find a more recent version at Firebird 5.0 Language Reference: EXCEPTION

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;
Prev: DECLARE [VARIABLE] with initializationFirebird Documentation IndexUp: PSQL statementsNext: EXECUTE PROCEDURE
Firebird Documentation IndexFirebird 1.5 Language Ref. UpdatePSQL statements → EXCEPTION