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 trytryTryTrytry 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 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_checkDevSetCheckDevSetCheckdev_set_check 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_dataDevGetExceptionDataDevGetExceptionDatadev_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 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 HTupleSequence[Union[int, str]]HTupleHtuple (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_dataDevGetExceptionDataDevGetExceptionDatadev_get_exception_data

See also

trytryTryTrytry, endtryendtryEndtryEndtryendtry, throwthrowThrowThrowthrow, dev_get_exception_datadev_get_exception_dataDevGetExceptionDataDevGetExceptionDatadev_get_exception_data, dev_set_checkdev_set_checkDevSetCheckDevSetCheckdev_set_check

Module

Foundation