Throwing an exception

If you detect an error or other situation in your message flow in which you want message processing to be terminated, you can throw an exception in a message flow in two ways:

  1. Use the ESQL THROW EXCEPTION statement.

    Include the THROW statement anywhere in the ESQL module for a Compute, Database, or Filter node. Use the options on the statement to code your own data to be inserted into the exception.

  2. Include a THROW node in your message flow.

    Set the node properties to identify the source and content of the exception.

Using either statement options or node properties, you can specify a message identifier and values that are inserted into the message text to give additional information and identification to users who interpret the exception. You can specify any message in any catalog that is available to the broker. See Using event logging from a user-defined extension for more information.

The situations in which you might want to throw an exception are determined by the behavior of the message flow; decide when you design the message flow where this action might be appropriate. For example, you might want to examine the content of the input message to ensure that it meets criteria that cannot be detected by the input node (which might check that a particular message format is received).

The example below uses the example Invoice message to show how you can use the ESQL THROW statement. If you want to check that the invoice number is within a particular range, throw an exception for any invoice message received that does not fall in the valid range.

--Check for invoice number lower than permitted range
IF Body.Invoice.InvoiceNo  < 100000 THEN
   THROW USER EXCEPTION CATALOG 'MyCatalog' MESSAGE 1234 VALUES
   ('Invoice number too low', Body.Invoice.InvoiceNo);

-- Check for invoice number higher than permitted range
ELSEIF Body.InvoiceNo > 500000 THEN
      THROW USER EXCEPTION CATALOG 'MyCatalog' MESSAGE 1235 VALUES
   ('Invoice number too high', Body.Invoice.InvoiceNo);

ELSE DO
  -- invoice number is within permitted range
  -- complete normal processing
ENDIF;
Related concepts
Message flows overview
ExceptionList tree structure
ESQL overview
Message modeling
Related tasks
Designing a message flow
Defining message flow content
Handling errors in message flows
Managing ESQL files
Related reference
Compute node
Database node
Filter node
ESQL reference
THROW statement