Error messages are represented by integer constants, the error codes of type Herror. If an error occurs, the corresponding error code should be returned by the procedure.
The file %HALCONROOT%\include\HErrorDef.h contains predefined error messages for all typical errors, see also appendix “HALCON Error Codes”. But it may happen that none of them fits an error occurring in a new, user-defined operator. So the user is allowed to define new codes that should be greater than 10 000 to avoid re-using an already allocated code or a code reserved for future extensions of the HALCON system. If the user-defined operator returns a user-defined error, the error will be reported as
No error message available for this error code (<error code>) .
In order to provide user-defined errors with error messages, the function HSetErrText
Herror HSetErrText(char *error_message)
can be called immediately before the operator returns the error code with return H_ERR_*. In this case the error message error_message will be displayed by the next11) call of the HALCON operator get_error_text.
Error codes are specified via #define and are called H_ERR_XYZ.
Examples:
H_ERR_WIPN1 /* wrong number of values in input control */
/* parameter 1 */
H_ERR_WIPV3 /* wrong parameter value (control param. 3) */
H_ERR_WIPT2 /* wrong type of values (control param. 2) */
H_ERR_WION1 /* wrong number of objects in input object */
/* parameter 1 */
H_ERR_WIT /* wrong image type */
H_MSG_TRUE /* no error (supply procedure) */
H_MSG_OK /* no error (any other procedure) */
All HALCON procedures return an error code. This code has to be checked after calling any HALCON procedure, e.g., by encapsulating the procedure call in the macro HCkP. This macro checks the return value and exits the current procedure if an error occurred (a detailed description of the macro is given in the section “HCkP”). Please note, that some of the Extension Package Interface macros described in chapter “Handling Iconic Objects and Control Parameters” and chapter “Special Routines for Typical Supply Procedures” (e.g. HGetCPar) implicitly use the macro and therefore automatically return a proper error code.
| 11) Within this call the error message is
reset to “No error message available ... ” again to ensure that the
user-defined error message is up to date.
|