User Tools

Site Tools


kb:bestpractices:codingconventions:errorhandling

04 Error Handling

The HSE Error Code Helper is a Quick Drop Plugin that helps with selecting (reusing) existing error codes as well as creating constant VIs for new error codes.

The HSE Logger allows the logging of errors when running the application.

Error Codes

  • Use the range reserved for user-defined errors (500000 – 599999)

For Loops

For loops can be quite tricky when it comes to error handling. The following chapter will describe why and how to avoid running into problems.

The number of iterations in a for loop is determined by either the numeric value wired to the counter terminal or the number of elements in an array wired to the for loop via an auto-indexing tunnel. If the numeric value is zero or the array is empty, the for loop is executed zero times. All output tunnels (Tunnel Modes: Last value, Auto Indexing, Concatenating) of the for loop will output their respective data type's default values and any previous values will be lost!

This is especially problematic if the wire contains references (which will be rendered invalid) or previous errors (which will lead to misinterpreting the original error source).

Options

Preserve incoming/last value

Using a shift register for wiring input/output tunnels will preserve the original (incoming) value or the value of the last executed iteration:

In case of an error, the code inside the loop might not execute for all following iterations.

Auto-index values

Enable Indexing on any output tunnel to create an array of values for each iteration:

In case of an error, the code inside the loop will still execute for all following iterations.

To keep previous values in addition to the output array, bypass the wire around the for loop and add it to the array after the for loop. For error clusters, you can use the Merge Errors node to wire the incoming error as the first element.

Timed Loops and Sequences

Always wire the error out of Timed Loops or Timed Sequence Structures as it can happen that those structures don't execute at all, for example if an invalid clock source was selected:


kb/bestpractices/codingconventions/errorhandling.txt · Last modified: 2024/08/09 07:47 by joerg.hampel