【发布时间】:2012-05-17 04:14:46
【问题描述】:
我无法弄清楚为什么我无法捕获 MS Chart 控件引发的异常。我正在使用带有最新更新的 Visual Studio 2010。感谢您的帮助。
以下是重现问题的方法:
- 创建一个新的 WinForms 应用程序
- 添加对 System.Windows.Forms.DataVisualization 的引用
- 在主窗体上放置一个按钮和一个图表控件
-
在表单的构造函数中添加以下代码
int[] x = new int[] { 1, 2, 3, 4, 5 }; int[] y = new int[] { 5, 13, 4, 10, 9 }; chart1.Series[0].Points.DataBindXY(x, y); -
在按钮的点击方法中添加如下代码
try { chart1.Series[0].Label = "#VAL{"; } catch { MessageBox.Show("Exception caught"); } - 运行应用程序
- 点击表单上的按钮
上面的 catch 块永远不会执行。相反,标签字符串中使用无效关键字引发的“InvalidOperationException”会冒泡到应用程序的 Main 方法。
【问题讨论】:
-
你是从另一个线程做的吗?
-
并非如此。重现我提到的问题的步骤使用标准的单线程 winforms 应用程序模板。
标签: c# visual-studio-2010 exception .net-4.0 mschart