ClassesClassesClassesClasses | | | | Operators

Page not available for the currently selected syntax (programming language).

Page not available for the currently selected syntax (programming language).

Page not available for the currently selected syntax (programming language).

Page not available for the currently selected syntax (programming language).

Page not available for the currently selected syntax (programming language).

catchT_catchCatchcatchCatchCatch (Operator)

Name

catchT_catchCatchcatchCatchCatch — Catches exceptions that were thrown in the preceding trytryTrytryTryTry block.

Signature

catch( : : : Exception)

Herror T_catch(Htuple* Exception)

Herror catch(HTuple* Exception)

void Catch(HTuple* Exception)

void HOperatorSetX.Catch([out] VARIANT* Exception)

static void HOperatorSet.Catch(out HTuple exception)

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_checkDevSetCheckdev_set_checkDevSetCheckDevSetCheck as well as in the “HDevelop User's Guide”.

The operator catchcatchCatchcatchCatchCatch ends a block of watched program lines and starts a blockof 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_dataDevGetExceptionDatadev_get_exception_dataDevGetExceptionDataDevGetExceptionData, 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 languages C and VisualBasic 6.0, but only for the languages C++, C# and VisualBasic/.NET. Only the latter support throwing exceptions across procedures.

Parameters

ExceptionExceptionExceptionExceptionExceptionexception (output_control)  exception-array HTupleHTupleHTupleVARIANTHtuple (integer / string) (int / long / string) (Hlong / HString) (Hlong / char*) (Hlong / BSTR) (Hlong / char*)

Tuple returning the exception data.

Result

catchcatchCatchcatchCatchCatch always returns 2 (H_MSG_TRUE).

Possible Successors

dev_get_exception_datadev_get_exception_dataDevGetExceptionDatadev_get_exception_dataDevGetExceptionDataDevGetExceptionData

See also

trytryTrytryTryTry, endtryendtryEndtryendtryEndtryEndtry, throwthrowThrowthrowThrowThrow, dev_get_exception_datadev_get_exception_dataDevGetExceptionDatadev_get_exception_dataDevGetExceptionDataDevGetExceptionData, dev_set_checkdev_set_checkDevSetCheckdev_set_checkDevSetCheckDevSetCheck

Module

Foundation


ClassesClassesClassesClasses | | | | Operators