Download HDevelop User's Manual
Transcript
CHAPTER 4. CODE GENERATION
86
One of these messages is always returned indicating the status of the operator. Normally, the
result is H MSG TRUE. Some operators return H MSG FAIL like read image or read region to
indicate that they could not open a file or there was no permission to read it. In this case the
programmer has to check the return value and apply some adequate action. If the message
H MSG FALSE is ignored, errors like
Halcon Error #4056: Image data management: object-ID is NULL
will happen in successive operators, because the predecessor operator did not calculate an appropriate value.
Errors In the case of hard errors (i.e., no message as described above) the program stops
with an error message. To prevent this behavior the HDevelop operators dev error var
and dev set check can be used to control the exception handling in the application. This
works similarly in HDevelop and C++. One difference is caused by the dynamic evaluation
of dev error var in HDevelop. This means that each time the operator is executed (e.g., in
a loop) the use of the error variable might change. In contrast to this, in C++ special code
is added to store the return values of operators. This code will therefore be static and cannot
change during program excecution. To understand how the code generation works let us have a
look at a short example. Here at first the HDevelop program:
dev_set_check(’~give_error’)
dev_error_var(error,true)
threshold(image,region,100,255)
dev_error_var(error,false)
if (error # H_MSG_TRUE)
write_string(WindowId,’error number = ’ + error)
exit()
endif
dev_set_check(’give_error’)
This program will be translated into
HTuple error;
::set_check("~give_error");
error = ::threshold(image,®ion,100,255);
if (error != 2)
{
::write_string(WindowId,HTuple("error number = ") + HTuple(error));
exit(1);
}
::set_check("give_error");
As can be seen, the operator dev error var is eliminated and replaced by the use of the error
variable later on.
The points mentioned above might cause these two problems:
• If the second parameter of dev error var cannot be derived from the program (because
no constant false or true are used but expressions, the value will be interpreted as true,
HDevelop, 2003-08-01