【发布时间】:2018-09-05 00:45:54
【问题描述】:
我正在编写一个LabVIEW VI,以便能够处理从C# 库中抛出的异常。我不知道如何使用错误集群读取异常消息以及如何处理退出应用程序。
我是这样写C#代码的:
// Make use of generic System library calls in this code.
using System.ComponentModel;
// Define the namespace for the following classes.
namespace NETEvents
{
// ProduceMyEvent is a class that will fire the event.
public class ProduceMyEvent : INotifyPropertyChanged
{
//Declare an internal variable. We will use this to fire events upon a changed value.
//Note that this value is private to the ProduceMyEvent class.
private int x;
// Fire the event when the value of x changes.
public int xValue
{
//Get the value of x.
get { return x; }
//Set x to be the new value and fire off the new event!
set { x = value;
if (x < 0) {
throw new System.Exception("x must be larger than 0 \n");
}
OnPropertyChanged("xValue"); }
}
// INotifyPropertyChanged implementation
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
if (PropertyChanged != null)
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(name));
}
#endregion
}
}
使用此代码,如果从 VI 将 x 设置为负数,则会引发异常。但是我的labview实现如下所示,没有捕获到异常;错误状态不正确,并且源为空。如何使用错误集群来读取 C# 抛出的异常?
【问题讨论】:
-
你在哪里传递从你的 c# 代码返回的值在 labview 中的读取?在哪里执行此操作,只需使用 case structure, or a selector,传递一个包含所需详细信息的新错误集群。
标签: c# .net error-handling labview