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.

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

catchT_catchCatchCatchcatch (Operator)

Name

catchT_catchCatchCatchcatch — Catches exceptions that were thrown in the preceding trytryTryTryTrytry block.

Signature

catch( : : : Exception)

Herror T_catch(Htuple* Exception)

void Catch(HTuple* Exception)

static void HOperatorSet.Catch(out HTuple exception)

def catch() -> Sequence[Union[int, str]]

Description

With the help of the operators trytryTryTryTrytry, catchcatchCatchCatchCatchcatch, endtryendtryEndtryEndtryEndtryendtry, and throwthrowThrowThrowThrowthrow 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 trytryTryTryTrytry, throwthrowThrowThrowThrowthrow, and dev_set_checkdev_set_checkDevSetCheckDevSetCheckDevSetCheckdev_set_check as well as in the “HDevelop User's Guide”.

The operator catchcatchCatchCatchCatchcatch 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 trytryTryTryTrytry-catchcatchCatchCatchCatchcatch block is executed without an exception, the catchcatchCatchCatchCatchcatch-endtryendtryEndtryEndtryEndtryendtry block is ignored and program execution continues after the corresponding endtryendtryEndtryEndtryEndtryendtry operator. In contrast, in an error case the program execution jumps directly from the operator where the error occurred (or from the throwthrowThrowThrowThrowthrow operator) to the catchcatchCatchCatchCatchcatch operator of the surrounding trytryTryTryTrytry-catchcatchCatchCatchCatchcatch block. The output control parameter ExceptionExceptionExceptionExceptionexceptionexception 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 throwthrowThrowThrowThrowthrow operator, an arbitrary user-defined tuple can be returned.

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

ExceptionExceptionExceptionExceptionexceptionexception (output_control)  exception-array HTupleSequence[Union[int, str]]HTupleHtuple (integer / string) (int / long / string) (Hlong / HString) (Hlong / char*)

Tuple returning the exception data.

Result

catchcatchCatchCatchCatchcatch always returns TRUE.

Possible Successors

dev_get_exception_datadev_get_exception_dataDevGetExceptionDataDevGetExceptionDataDevGetExceptionDatadev_get_exception_data

See also

trytryTryTryTrytry, endtryendtryEndtryEndtryEndtryendtry, throwthrowThrowThrowThrowthrow, dev_get_exception_datadev_get_exception_dataDevGetExceptionDataDevGetExceptionDataDevGetExceptionDatadev_get_exception_data, dev_set_checkdev_set_checkDevSetCheckDevSetCheckDevSetCheckdev_set_check

Module

Foundation