LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I programmatically change an error message?

In the attached vi, I tried to edit the error message that is generated by LabVIEW.  But instead, my text is added to the list of Possible Reason(s) displayed in the error message.  Can I programmatically change an error message that is generated by LabVIEW?

0 Kudos
Message 1 of 15
(4,476 Views)

The easiest way would simply be to replace the error cluster with the value you want. In addition you can use the Bundle by Name cluster primative to replace the error string with your own message. Wire the error into the input



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 2 of 15
(4,473 Views)

It can be done like this

Tim
GHSP
Message 3 of 15
(4,469 Views)

Thanks, but I'm concerned about modifying the error description that appears in the error message generated from the General Error Handler.

0 Kudos
Message 4 of 15
(4,450 Views)

The example that I gave you only changes the error code for the one error that is identified in the case otherwise it passes the orginal error information.

Tim
GHSP
Message 5 of 15
(4,447 Views)

@Vi Joe wrote:

Thanks, but I'm concerned about modifying the error description that appears in the error message generated from the General Error Handler.


I think I understand-  Try the topic on

Defining Custom Error Codes

The following ranges of error codes are reserved for you to define custom error messages:

  • -8999 through -8000
  • 5000 through 9999
  • 500,000 through 599,999

Complete the following steps to define custom error codes.

  1. Add the General Error Handler VI to the block diagram.

     Add  Find
  2. Right-click the [user-defined codes] input and select Create»Constant from the shortcut menu. An array appears.
  3. Double-click the numeric constant and enter a number within the range of -8999 to -8000, 5000 to 9999, or 500,000 to 599,999 in the array. For example, enter 5008.
  4. Right-click the [user-defined descriptions] input and select Create»Constant from the shortcut menu. Another array appears.
  5. Double-click the string constant and enter a description in the user-defined description array. For example, enter Ignore this message.
  6. Right-click the error in input and select Create»Constant from the shortcut menu. A cluster appears that contains a Boolean constant, a numeric constant, and an array.
  7. Use the Operating tool to set the Boolean control to TRUE.
  8. Double-click the numeric constant and enter the same number that appears in the [user-defined codes] constant.
Note  As an alternative to steps 6 through 8, you can wire a numeric constant with a value of 5008 to the Error Cluster From Error Code VI. Then wire the error out output of the Error Cluster From Error Code VI to the error in input of the General Error Handler VI.
  1. Run the VI. An error dialog appears and displays the customized error code and description. Click the Continue button in this error dialog.
  2. Double-click the General Error Handler subVI and view the front panel. Switch to the VI in which you defined your custom error code, and run the VI again. Notice that the message text box on the front panel of the General Error Handler VI displays the same customized error code and description as the error dialog.

You also can define custom error codes by creating an XML-based text file and adding the error codes and messages to the text file.

 

And

National Instruments recommends that you use the General Error Handler VI to define custom error codes in the range of -8999 through -8000, 5000 through 9999, or 500,000 through 599,999. However, you also can define custom error codes in the same range using the Error Code File Editor dialog box. Use this method if you want to use the same custom error codes with several VIs or if you want to distribute custom error codes with an application or shared library. If you want to distribute the custom error codes with an application or shared library, you must distribute the error code text files.

Complete the following steps to define custom error codes using the Error Code File Editor.

  1. Select Tools»Advanced»Edit Error Codes to launch the Error Code File Editor.
  2. In the prompt that appears, click the New button to create a new error codes file or click the Open button to browse to an existing error codes file.
  3. Enter comments about the error codes file in the Comments about this file text box.
  4. Click the Add button to add an error code and description to the error codes file.
  5. After you create new error codes, you can select and edit the error code descriptions using the Error code and Error text controls.
  6. When you are done editing the error codes file, select File»Save to save the error codes file in the labview\user.lib\errors directory. You must save the error codes file in the format xxx-errors.txt, where xxx is a name that you supply.

You also can define custom error codes in the same range by creating an XML-based text file. You must name the text file xxx-errors.txt, where xxx is a name that you supply. The xxx-errors.txt file must use the following syntax exactly, including capitalization, spacing, and so on. You supply the italic text:

<?xml version="1.0"?>
<nidocument>
<nicomment>

This file describes custom errors for my VI.
</nicomment>
<nierror code="
5000">
Memory full.
Add more memory.

</nierror>
<nierror code="
5001">
Invalid name. Enter a new name.
</nierror>
</nidocument>

You can add your own comment between the <nicomment></nicomment> tags. In each <nierror> tag, you must define the error code number. Define the error code message between the <nierror></nierror> tags.

Changes to error code text files take effect the next time you start LabVIEW.


"Should be" isn't "Is" -Jay
Message 6 of 15
(4,442 Views)

@Vi Joe wrote:

Thanks, but I'm concerned about modifying the error description that appears in the error message generated from the General Error Handler.


No only that you are not permanently changing the error message. You are only changing it when you us it in this vi for this instance that it is called. You are not changing it in LabVIEW permanently.

Tim
GHSP
Message 7 of 15
(4,436 Views)

I strongly advise against placing your own error description in the "source" field of the error cluster.  As the name implies, this field should only contain the call chain indicating where an error happened.  If you want to create your own error code and description, you should do so by creating an error code file (Tools >> Advanced >> Edit Error Codes...).  You can then generate an error with Error Cluster From Error Code.vi with your custom error code wired in.

 

Chris M

Message 8 of 15
(4,430 Views)

Thanks to everyone's help, I think the attached vi meets my needs - unless someone has a better idea.

0 Kudos
Message 9 of 15
(4,412 Views)

You do not need the outer case structure around the code. It is just extra.

Tim
GHSP
Message 10 of 15
(4,407 Views)