Navigation:  NexusDB Guide > SQL Reference > SQL Statements > Control Statements >

TRY statement

Previous pageReturn to chapter overviewNext page

NexusDB V3 Manual

TRY statement

button_main button_prev button_next

NexusDB Manual V3 > SQL Reference > SQL Statements > Control Statements

Specify a TRY..CATCH block.

 

Syntax

 

<try statement> ::=

 

 

 

TRY <protected statement block> <catch clause>... END

<protected statement block> ::= <SQL statement list>

 

<catch clause> ::= CATCH error-condition [ <catch statement block> ]

 

<catch statement block> ::= <SQL statement list>

 

 

Usage

 

The TRY statement is used to protect a block of SQL statements, and handle some or all of the possible errors that might occur during the execution, gracefully in SQL code. The concept is similar to TRY statements found in many programming languages.

 

 

Notes

 

§

Several CATCH clauses may be specified, but at least one is required.

 

§

A specific error-condition can be determined by evaluating the current error message using the ERROR_MESSAGE system function.

 

§

The statement block of the first CATCH clause that evaluates to true is executed.

 

§

If none of the CATCH clauses evaluates to true, then the current exception is raised.

 

 

Examples

 

1)

The following example shows the TRY statement used to control an explicit transaction:

 

      START TRANSACTION;

      TRY

// Execute some data-change statements here.

COMMIT;

      CATCH POSITION( 'Unable to open table' IN ERROR_MESSAGE ) <> 0

ROLLBACK;

SIGNAL ERROR_MESSAGE;

      END;

 

 


Conformance

 

NexusDB extensions

-

TRY statement

 

© Nexus Database Systems Pty Ltd.

nexus_logo