You are here: Start » Tutorial Exercises » ADVANCED: Error handling (error_handling)

ADVANCED: Error handling (error_handling)

Aim

Create a task macrofilter which contains a single error handler. This error handler should set a different value on an macrofilter output if any error occurs.

Create a simple HMI with two Label controls and a single Knob control.

Input

The value set by user on an HMI.

Output

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.

Hints

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 to continue program when Domain Error will be handled.

Domain Error is often raised in answer to setting value that lays 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 comes 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.

Solution (AVS)

  1. Create a new Task macrofilter Divide.

  2. Add filter DivideIntegers to Divide 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 filter DivideIntegers to macrofilter's inputs and outputs.

  3. Add a new error handler of type "DOMAIN_ERROR" to the Divide macrofilter.

    Selecting the error handling type:

  4. Enter to DOMAIN_ERROR error handler and set a constant output value to ,,Error``.

  5. Add two labels to HMI. Set first text value to Result:. Connect inText of second label to outQuotient of macrofilter Divide.

  6. To HMI form add Knob control and set its Value to 10 to avoid getting an exception on the application start. Connect its outValue to inB of macrofilter Divide.

  7. Execute application and set knob value to 0. In result, exception will occur as on the image below. Note that label will be set to Error after clicking on the button continue.

  8. Add Loop filter to execute 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.