0% found this document useful (0 votes)
191 views

LabVIEW Error Handling PDF

Uploaded by

Bharath yk
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
191 views

LabVIEW Error Handling PDF

Uploaded by

Bharath yk
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Error Checking and Error Handling

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.

Automatic Error Handling


Each error has a numeric code and a corresponding error message.

By default, LabVIEW automatically handles any error when a VI runs by suspending


execution, highlighting the subVI or function where the error occurred, and displaying an
error dialog box.

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.

Manual Error Handling


Use the LabVIEW error handling VIs and functions on the Dialog & User Interface
palette and the error in and error out parameters of most VIs and functions to manage
errors. The error handling VIs let you display the error message in different kinds of dialog
boxes.

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:

• status is a Boolean value that reports TRUE if an error occurred.


• code is a 32-bit signed integer that identifies the error numerically. A nonzero error
code coupled with a status of FALSE signals a warning rather than a error.
• source is a string that identifies where the error occurred.

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.

Figure 1: Error Checking in a top-level VI

Error Handling in subVIs


Essential programming practice is making sure all executable code can manage error
conditions. In programs intended to be used as subVIs it is recommended that no pop-up
dialog functions be used, instead, an error cluster should be provided as an output
parameter.

Figure 2: Error Management in a SubVI

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.

Figure 3: Standard Connector Pane Setup

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

You might also like