The macro HCkP (see figure 5.39) checks the result state of a procedure call. Most of the HALCON procedures are of the type Herror. For internal HALCON procedures, the result code H_MSG_OK is returned if no error occurred, see also section “Error Handling”. HCkP exits the current procedure if the encapsulated procedure returns any other error code. Moreover, this error code is returned to the caller of the current procedure.
The macro is used to make source code more compact, but still safe with respect to error handling, see figure 5.40: Here, the call of the procedure HRLDecomp is encapsulated within the macro. If any error occurs, the procedure exits with an appropriate error code. Otherwise the processing is continued.
Note that most of the interface routines described in this chapter internally call HCkP, i.e. they exit the current procedure returning an appropriate error code in case of an error.
Be aware that all memory permanently allocated within a procedure will not be deallocated in case of an error if you exit the procedure using HCkP. This will lead to memory leaks.
Herror err; /* without HCkP: */ err = HRLDecomp(reg_in,r1,c1,r2,c2, reg_inner,reg_outer); if (err != H_MSG_OK) return err; /* with HCkP: */ HCkP(HRLDecomp(reg_in,r1,c1,r2,c2, reg_inner,reg_outer));
Figure 5.40: Error handling with HCkP.