Icon EXCEPTION

Declares a block of statements for handling an exception.

Syntax
[Label:]
BEGIN
   [<Statement>;]
   [<Statement>;]
EXCEPTION
   [<Statement>;]
END [Label];

Usage
Use these statements to declare a block of statements for execution in a procedure or function with an associated exception block of statements for handling any exceptions that may occur in the block of statements.

You can use the ERRORCODE and ERRORMSG functions in an exception handling block to determine the current error code and message.

Examples
-- This procedure uses an EXCEPTION
-- block to handle any exceptions while
-- executing a CREATE TABLE statement

CREATE PROCEDURE CreateTestTable()
BEGIN
   DECLARE stmt STATEMENT;

   PREPARE stmt FROM 'CREATE TEMPORARY TABLE "TestTable"
                     (
                     "FirstColumn" INTEGER,
                     "SecondColumn" VARCHAR(30),
                     "ThirdColumn" CLOB,
                     PRIMARY KEY ("FirstColumn")
                     )

                     DESCRIPTION ''Test Table''';

   EXECUTE stmt;
EXCEPTION
   IF ERRORCODE()=700 THEN
      RAISE ERROR CODE 10000 MESSAGE 'Syntax error';
   ELSE
      RAISE ERROR CODE 10000 MESSAGE 'Unexpected error - ' +
           ERRORMSG();
   END IF;
END

SQL 2003 Standard Deviations
This statement deviates from the SQL 2003 standard in the following ways:

DeviationDetails
ExtensionThis SQL statement is an ElevateDB extension.
Image