EXCEPTION

<< DECLARE | FB 2.5 Language Reference | EXECUTE PROCEDURE >>
<< DECLARE | FB 2.1 Language Reference | EXECUTE PROCEDURE >>
<< DECLARE | FB 2.0 Language Reference | EXECUTE PROCEDURE >>

EXCEPTION

Available in: PSQL

Changed in: 1.5

Description

The EXCEPTION syntax has been extended so that the user can

a. Rethrow a caught exception or error.
b. 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.

back to top of page
<< DECLARE | FB 2.5 Language Reference | EXECUTE PROCEDURE >>
<< DECLARE | FB 2.1 Language Reference | EXECUTE PROCEDURE >>
<< DECLARE | FB 2.0 Language Reference | EXECUTE PROCEDURE >>