ADVANCED: Error handling (error_handling)
Create a task macrofilter which contains a single error handler. This error handler should set a different value on a macrofilter output if any error occurs.
Create a simple HMI with two Label controls and a single Knob control.
The value set by a user on an HMI.
The HMI with a single Knob and two Label controls. One of the Label should be set to a computed value or text Error when any problem occurred.
Task macrofilters can contain error handlers which are executed when an error occurred. The behavior of each error handler depends on the severity of the exception.
In this example only DomainError error will be raised. Adaptive Vision Studio allows a program to continue when Domain Error will be handled.
Domain Error is often raised in answer to setting value that lies out of operation domain. For example when a divisor is set to 0 during the integer division operation. In this example a filter DivideIntegers is the source of exception. In real appliance most exceptions come from problems with hardware.
Error handling is a quite computational complex operation. Avoid usage of the error handling as an answer to invalid parameter set on an input.
Labeling connections is explained in this article.
Create a new Task macrofilter in PROCESS section. You can name it Divide.
Add the DivideIntegers filter into Divide's PROCESS section and create inputs and outputs the same as in the added filter (inA, inB and outQuotient). The output outQuotient should be of type String to handle with Error message. Connect inputs and outputs of the DivideIntegers filter to macrofilter's inputs and outputs.
Add a new error handler of "DOMAIN_ERROR" type to the Divide macrofilter.
Selecting the error handling type:
Enter to DOMAIN_ERROR error handler and set a constant output value to "Error".
Add two labels to HMI. Set first text value to Result:. Connect inText of second label to outQuotient of macrofilter Divide.
Add Knob control to the HMI form and set its Value to 10 to avoid getting an exception during the launch of application. Connect its outValue to inB of the Divide macrofilter.
Execute the application and set the knob value to 0. In result, exception will occur as in the image below. Note that label will be set to Error after clicking on the button Continue.
Add the Loop filter to run the application in an endless loop.
Error handling is a quite computational complex operation. Try to avoid its usage only to managing of the hardware problems.
Macrofilter Main communicates with the HMI.
Macrofilter Divide divides two integer values.
Error handler DOMAIN_ERROR of macrofilter Divide sets an Error value on an output.