Throw an exception.

throw ErrorNumber {, Description {, AdditionalInformation} }

Example: throw -10050, "No privilege to access Customer information", "USERID=%%(ID.USER);USERNAME=%%(NAME.USER)"


Parameter Data Type Description
ErrorNumber Numeric The error number. Positive numbers are thrown as negative numbers. 0 is thrown as -1 <UGENERR_ERROR>.

To avoid confusion, use numbers outside the range -1 though -9999, which are reserved for Uniface errors.

Description String A brief, mnemonic-like description.
AdditionalInformation String More detailed information about the error.

Return Values

After the throw statement, $procerror has the value that was specified in the ErrorNumber argument, and $procerrorcontext has items with IDs DESCRIPTION and ADDITIONAL, which have the values of the Description and AdditionalInformation arguments respectively.

If Description is omitted, $procerrorcontext will have a DESCRIPTION item with the value Custom exception.

If AdditionalInformation is omitted, $procerrorcontext will have no ADDITIONAL item.


Allowed in all component types.


The throw statement enables you to throw a custom exception without affecting system exceptions, so that you can use the exception bubble to handle custom errors.

Error numbers are always negative numbers, so the provided ErrorNumber should be a negative number. If it is a positive number, the throw statement will throw it as a negative number. If the provided ErrorNumber is zero, the throw statement will throw error -1 <UGENERR_ERROR>.

The throw statement stops execution of the current block of code. If it is located:

  • Inside a try...catch...endtry block, code execution continues in one of the associated catch blocks, if there is an applicable one. If not, the exception bubbles up to the next try-level or to the caller of the module.
  • Outside a try...catch...endtry block but in a ProcScript module that has the throws clause, code execution continues within the calling module, with the statement following the call to this module.
  • Outside a try...catch...endtry block, in a ProcScript module that does not have the throws clause, the ProcScript compiler returns an error:

    error: 1000 - "throw" statement only allowed inside a try block or in a module declared as throws

For example:

public operation loadOrder
  string pOrderId : IN
  if (pOrderId == "")
    throw -10001, "Invalid input parameter", "PARAM_INDEX=1;PARAM_NAME=pOrderId;EXPECTED_VALUE=Not NULL"
  ID.ORDER/init = pOrderId
  retrieve/e "ORDER"