我正在编写一个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
}
}
使用此代码,如果x从VI设置为负数,则抛出异常。但是我的labview实现如下所示,例外情况并未被发现;错误状态不为true,源也为空。如何使用错误集群来读取从C#抛出的异常?
答案 0 :(得分:0)