catch — Catches exceptions that were thrown in the preceding try block.
catch( : : : Exception)
With the help of the operators try, catch, endtry, and throw it is possible to implement a dynamic exception handling in HDevelop, which is comparable to the exception handling in C++ and C#. The basic concepts of the exception handling in HDevelop are described at the operators try, throw, and dev_set_check as well as in the “HDevelop User's Guide”.
The operator catch ends a block of watched program lines and starts a blockof program lines that have to be executed in an error case. If the try-catch block is executed without an exception, the catch-endtry block is ignored and program execution continues after the corresponding endtry operator. In contrast, in an error case the program execution jumps directly from the operator where the error occurred (or from the throw operator) to the catch operator of the surrounding try-catch block. The output control parameter Exception returns a tuple that contains a predefined set of data describing the error in case an operator error occurred. If the exception was thrown by the throw operator, an arbitrary user-defined tuple can be returned.
The most important data within the Exception tuple is the error code. Therefore, this is passed as the first item of the Exception tuple and can be accessed directly with 'Exception'. However, all other data has to be accessed through the operator dev_get_exception_data, because the order and the extent of the provided data may change in future versions and may vary for different programming language exports. Especially, it has to be taken into account that in the exported code there are some items of the error tuple that are not available and others that might not be determined until they are requested (like error messages).
If the exception was thrown by an operator error, a HALCON error code (< 10000) or if the aborted operator belongs to an extension package, a user-defined error code (> 10000) is returned as the error code. A list of all HALCON error codes can be found in the appendix of the “Extension Package Programmer's Manual”. The first element of a user-defined Exception tuple thrown by the operator throw should be an error code >= 30000. Additional tuple elements can be chosen without any restrictions.
If an operator error occurred within HDevelop or HDevEngine, the following information about the error is provided by the Exception tuple:
The HALCON error code.
An additional HDevelop specific error code that specifies whether an error was caught within the HALCON operator (code = 21000) or outside the operator, e.g., during the evaluation and assignment of the parameter expressions. In the latter case the error code specifies the kind of error more precisely.
The HALCON error message.
An appropriate HDevelop-specific error message.
The number of the program line, where the error occurred.
The name of the operator that threw the exception (if the exception was thrown in a protected procedure, '--protected--' is returned instead of the operator name).
The depth of the call stack (if the error occurred in 'main' a depth of 1 is returned).
The name of the procedure, where the error occurred.
In most cases, for an automatic exception handling it is sufficient to use the HALCON error code. Additional data is primarily passed in order to provide some information about the error condition to the developer of the HDevelop program for debugging reasons. Attention: in the exported code, in general, information about the error location will not be available.
The export of the operators try, catch, endtry, and throw is not supported for the language C, but only for the languages C++, C# and VisualBasic/.NET. Only the latter support throwing exceptions across procedures.
Tuple returning the exception data.
catch always returns 2 (H_MSG_TRUE).
try, endtry, throw, dev_get_exception_data, dev_set_check