LabVIEW Error Handling PDF
LabVIEW Error Handling PDF
No matter how confident you are in the VI you create, you cannot predict every problem a
user can encounter. Without a mechanism to check for errors, you know only that the VI
does not work properly. Error checking tells you why and where errors occur.
To disable automatic error handling for the current VI, select File»VI Properties and select
Execution from the Category pull-down menu. To disable automatic error handling for
any new, blank VIs you create, select Tools»Options and select Block Diagram from the
Category list. To disable automatic error handling for a subVI or function within a VI, wire
its error out parameter to the error in parameter of another subVI or function or to an
error out indicator.
VIs and functions return errors in one of two ways—with numeric error codes or with an
error cluster. As a rule of thumb, functions use numeric error codes, and VIs use an error
cluster.
Almost all I/O functions return error information. Include error checking in VIs, especially
for I/O operations (file, serial, instrumentation, data acquisition, and communication), and
provide a mechanism to handle errors appropriately.
Error Clusters
Use the error cluster controls and indicators to create error inputs and outputs in subVIs.
The error in and error out clusters include the following components of information:
Error handling in LabVIEW follows the dataflow model. Just as data values flow through a
VI, so can error information. Wire the error information from the beginning of the VI to the
end. Include an error handler VI at the end of the top-level VI to determine if the VI and its
subVIs ran without errors. Use the error in and error out clusters in each VI you use or
Error Checking and Error Handling page 1 (3) © National Instruments Corporation
build to pass the error information through the VI. See Figure 1 below for an example on a
top-level VI error handling.
As the VI runs, LabVIEW tests for errors at each execution node. If LabVIEW does not
find any errors, the node executes normally. If LabVIEW detects an error, the node passes
the error to the next node, but code is no longer executed. The next node does the same
thing, and so on. At the end of the execution flow, LabVIEW reports the error.
Error cluster should also be provided as an input parameter to a subVI, on one hand, to
ensure data flow, on the other, to avoid unnecessary execution of the code in case of an
error in the preceding functions. For a simple example on how to manage this, see Figure
2. Error in has been wired directly to a case structure that contains all executable code in
Error Checking and Error Handling page 2 (3) © National Instruments Corporation
the subVI. This approach ensures effective program execution since the subVI exits as
quickly as possible if an error has occurred in a previous stage in the main VI.
The most commonly used way of connecting the error inputs and outputs in the connector
pane is indicated in Figure 3. The top inputs and outputs are commonly used for passing
references and the bottom inputs and outputs are used for error handling.
Explain Error
When an error occurs, right-click within the cluster border and select Explain Error from
the shortcut menu to open the Explain Error dialog box. The Explain Error dialog box
contains information about the error. The shortcut menu includes an Explain Warning
option if the VI contains warnings but no errors1.
You also can access the Explain Error dialog box from the Help»Explain Error menu.
VIs and functions return errors in one of two ways—with numeric error codes or with an
error cluster. Typically, functions use numeric error codes, and VIs use an error cluster,
usually with error inputs and outputs.
1
If the ’status’ parameter of the error cluster is FALSE, we treat the information as a
warning rather than error. The code can still be passed on but all code will be executed in
the following VIs.
Error Checking and Error Handling page 3 (3) © National Instruments Corporation