Transcription of LabVIEW Error Handling - Aalto
1 Error Checking and Error Handling page 1 (3) national instruments Corporation 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.
2 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.
3 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.
4 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 2 (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.
5 At the end of the execution flow, LabVIEW reports the Error . 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 Figure 1: Error Checking in a top-level VI Error Checking and Error Handling page 3 (3) national instruments Corporation the subVI.
6 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.
7 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.