THROW statement

The THROW statement generates a user exception.

SYNTAX

The USER keyword indicates the type of exception being thrown. (Currently, only USER exceptions are supported, and if you omit the USER keyword the exception defaults to a USER exception anyway.) Specify the USER keyword, even though it currently has no effect, for the following reasons:
  • If future broker releases support other types of exception, and the default type changes, your code will not need to be changed.
  • It makes it clear that this is a user exception.

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 Message Broker current version catalog. To use the current WebSphere Message Broker version message catalog explicitly, use BIPV600 on all operating systems.

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 Message Broker catalog (2951). If you enter a message number in the THROW statement, you can use message numbers 2951 to 2999. Alternatively, you can generate your own catalog by following the instructions in Using event logging from a user-defined extension.

Use the optional VALUES field to insert data into your message. You can insert any number of pieces of information, but the messages supplied (2951 - 2999) cater for eight inserts only.

Examples

Here are some examples of how you might use a THROW statement:
  • THROW USER EXCEPTION; 
  • THROW USER EXCEPTION CATALOG 'BIPv600' MESSAGE 2951 VALUES(1,2,3,4,5,6,7,8) ;
  • THROW USER EXCEPTION CATALOG 'BIPv600' MESSAGE 2951 VALUES('The SQL State: ', 
        SQLSTATE, 'The SQL Code: ', SQLCODE, 'The SQLNATIVEERROR: ', SQLNATIVEERROR, 
        'The SQL Error Text: ', SQLERRORTEXT ) ;
  • THROW USER EXCEPTION CATALOG 'BIPv600' MESSAGE 2951 ;
  • THROW USER EXCEPTION CATALOG 'MyCatalog' MESSAGE 2951 VALUES('Hello World') ;
  • THROW USER EXCEPTION MESSAGE 2951 VALUES('Insert text 1', 'Insert text 2') ;

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 overview
Related tasks
Developing ESQL
Throwing an exception
Related reference
Syntax diagrams: available types
ESQL statements
ESQL database state functions