Use the tabs on the upper right to switch to a different programming language.

Use the tabs on the upper right to switch to a different programming language.

Use the tabs on the upper right to switch to a different programming language.

catchT_catchCatchCatch (Operator)

Name

catchT_catchCatchCatch — Catches exceptions that were thrown in the preceding trytryTryTryTry block.

Signature

catch( : : : Exception)

Herror T_catch(Htuple* Exception)

void Catch(HTuple* Exception)

static void HOperatorSet.Catch(out HTuple exception)

Description

With the help of the operators trytryTryTryTry, catchcatchCatchCatchCatch, endtryendtryEndtryEndtryEndtry, and throwthrowThrowThrowThrow 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 trytryTryTryTry, throwthrowThrowThrowThrow, and dev_set_checkdev_set_checkDevSetCheckDevSetCheckDevSetCheck as well as in the “HDevelop User's Guide”.

The operator catchcatchCatchCatchCatch ends a block of watched program lines and starts a block of program lines that have to be executed in an error case. If the trytryTryTryTry-catchcatchCatchCatchCatch block is executed without an exception, the catchcatchCatchCatchCatch-endtryendtryEndtryEndtryEndtry block is ignored and program execution continues after the corresponding endtryendtryEndtryEndtryEndtry operator. In contrast, in an error case the program execution jumps directly from the operator where the error occurred (or from the throwthrowThrowThrowThrow operator) to the catchcatchCatchCatchCatch operator of the surrounding trytryTryTryTry-catchcatchCatchCatchCatch block. The output control parameter ExceptionExceptionExceptionExceptionexception 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 throwthrowThrowThrowThrow operator, an arbitrary user-defined tuple can be returned.

The most important data within the ExceptionExceptionExceptionExceptionexception tuple is the error code. Therefore, this is passed as the first item of the ExceptionExceptionExceptionExceptionexception tuple and can be accessed directly with 'Exception'"Exception""Exception""Exception""Exception"[0]. However, all other data has to be accessed through the operator dev_get_exception_datadev_get_exception_dataDevGetExceptionDataDevGetExceptionDataDevGetExceptionData, 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 ExceptionExceptionExceptionExceptionexception tuple thrown by the operator throwthrowThrowThrowThrow 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 ExceptionExceptionExceptionExceptionexception tuple:

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.

Attention

The export of the operators trytryTryTryTry, catchcatchCatchCatchCatch, endtryendtryEndtryEndtryEndtry, and throwthrowThrowThrowThrow 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.

Parameters

ExceptionExceptionExceptionExceptionexception (output_control)  exception-array HTupleHTupleHtuple (integer / string) (int / long / string) (Hlong / HString) (Hlong / char*)

Tuple returning the exception data.

Result

catchcatchCatchCatchCatch always returns 2 (H_MSG_TRUE).

Possible Successors

dev_get_exception_datadev_get_exception_dataDevGetExceptionDataDevGetExceptionDataDevGetExceptionData

See also

trytryTryTryTry, endtryendtryEndtryEndtryEndtry, throwthrowThrowThrowThrow, dev_get_exception_datadev_get_exception_dataDevGetExceptionDataDevGetExceptionDataDevGetExceptionData, dev_set_checkdev_set_checkDevSetCheckDevSetCheckDevSetCheck

Module

Foundation