Error handling🔗
This section describes how errors are handled in HALCON Script programs.
When an error occurs, the default behavior of HDevelopEVO is to stop the program execution and display an error message. While this is certainly beneficial at the time the program is developed, it is usually not desired when the program is actually deployed. A finished program should react to errors itself. This is of particular importance if the program interacts with the user.
HDevelopEVO supports dynamic exception handling, which is comparable to the exception handling in C++ and C#.
A block of program lines is watched for run-time errors. If an error occurs, an exception is raised and an associated exception handler is called. An exception handler is just another block of program lines, which is invisible to the program flow unless an error occurs. The exception handler can directly act on the error, or it can pass the associated information (the exception) on to a parent exception handler. This is also known as rethrowing an exception.
An HDevelopEVO exception is a tuple containing data related to a specific error. It always contains the error code as the first item.
HDevelopEVO exception handling is applied in the following way:
...
try
* start block of watched program lines
...
catch(Exception)
* get error code
ErrorCode := Exception[0]
* react to error
endtry
* program continues normally
...