THROW statement

The THROW statement generates a user exception causing the transaction to be rolled back.

Syntax

SEVERITY is an optional clause that determines the severity associated with the exception. The clause can contain any expression that returns a non-NULL, integer value. If you omit the clause, it defaults to 1.

CATALOG is an optional clause; if you omit it, it defaults to the WebSphere Business Integration Message Broker version catalog.

MESSAGE is an optional clause; if you omit it, it defaults to the first message number of the block of messages provided for using THROW statements in WebSphere Business Integration Message Broker catalog (2949). If you enter a message number in the THROW statement, you can use message numbers 2949 to 2999. Alternatively, you can generate your own catalog.

Use the optional VALUES field to insert data into your message. You can insert any number of pieces of information, but the messages supplied (2949 - 2999) cater for eight inserts only. For information about SQLSTATE and SQLCODE, see ESQL database state functions.

Examples

Here are some examples of how you might use a THROW statement:
  • THROW USER EXCEPTION; 
    This means that there are no inserts.
  • THROW USER EXCEPTION CATALOG 'WMQIv210' MESSAGE 2949 VALUES(1,2,3,4,5,6,7,8) ;
  • THROW USER EXCEPTION CATALOG 'WMQIv210' MESSAGE 2949 VALUES('The SQL State: ', 
        SQLSTATE, 'The SQL Code: ', SQLCODE, 'The SQLNATIVEERROR: ', SQLNATIVEERROR, 
        'The SQL Error Text: ', SQLERRORTEXT ) ;
  • THROW USER EXCEPTION CATALOG 'WMQIv210' MESSAGE 2949 ;
  • THROW USER EXCEPTION CATALOG 'MyCatalog' MESSAGE 1234 VALUES('Hello World') ;

You can use the THROW statement at any time: you do not have to use database state indicators.

For more information about how to throw an exception, and details of SQLSTATE, SQLCODE, SQLNATIVEERROR, and SQLERRORTEXT, see ESQL database state functions.

Related concepts
ESQL
Related tasks
Developing ESQL
Throwing an exception
Related reference
Syntax preference
ESQL statements
ESQL database state functions