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.

Handle all errors

Wire all error terminals!

This is one of our most profound and important conventions: No unexpected behaviour should go unnoticed! Make not wiring an error out the exception, and document why it's unwired.

There are no exceptions to this rule at this time.

Error Message Formatting

  • Make the source string more readable by appending variables/values to the actual problem instead of placing them in the middle of the string:
    • “File not found: %s” instead of “File %s not found”

Error Codes

HSE Error Ranges

The HSE Error Code Ranges are maintained in their own repository. There are two main ranges:

Type Range
Generic reuse components 500.000 - 559.999
Project-specific components 560.000 - 579.999

How to Select a Range

When creating a new DQMH module, class or library:

  1. Consider the type (generic reuse vs. project-specific) and assign an error range accordingly
  2. The default range is 100 error codes per component (eg 568.200 - 568.299)
    • This allows the first four digits to uniquely identify a module or library, making it easier to scan error codes without mental arithmetic.

Example:

Module Range
Module A 560.1xx
Module B 560.2xx
Module C 560.3xx

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:


The HSE Way of Working:
A set of guidelines that recommend programming style, better practices, and methods for all our LabVIEW projects. We ask all our peers to follow these guidelines to help improve the readability of our shared source code and make software maintenance easier.

kb/bestpractices/codingconventions/errorhandling.txt · Last modified: 2026/08/19 13:03 by joerg.hampel