Top  Previous  Next


The THROW statement throws an exception that can be caught in a TRY / CATCH construct.





THROW exception {, data}




exceptionis the case insensitive name of the exception to be thrown. This may be a quoted constant value or an expression that evaluates to the exception name.



An exception is a named event, typically an error, raised within an application by use of the THROW statement and caught by a TRY/CATCH construct elsewhere in the application. The actual name has no significance to QM but should ideally relate to the situation that the exception handles. See Exception Handling for further information on exception names.


The @EXCEPTION variable is set to contain the name of the exception being thrown and @EXCEPTION.ORIGIN is set to a dynamic array in which field 1 holds the program name and field 2 holds the line number at which the exception was thrown. If the program has no cross-reference tables, the line number will be -1.


The optional data element of this statement is an expression that will be evaluated and stored in @EXCEPTION.DATA. This may be a simple data item such as a number or a string, or it can be a complex data item such as a file variable, a socket or an instance of a class. In the case of complex items, it may be necessary for the exception handler to clear @EXCEPTION.DATA after any processing so that, for example, the file associated with a file variable can be closed.


If the data element is omitted, @EXCEPTION.DATA is set to a null string.


If an exception is thrown for which there is no corresponding TRY/CATCH exception handler, an abort occurs.







The above statement throws an exception named ACCOUNT.INVALID.



See also: