我已经使用SeriesChartType列表填充了一个组合框 . 这允许用户选择想要查看的图表类型 . 这很好用 . 但是,当存在多个系列时,或者如果存在不同数量的数据点,则某些图表类型会抛出异常 .

例如 . System.InvalidOperationException:'Renko图表类型 - 无法将此图表类型与任何其他图表组合 .

困难的部分是我似乎无法捕获异常 . 当我尝试更新图表时它会被抛出,所以我尝试了以下方法:

try
        {
            Series1.ChartType = (SeriesChartType)Cmb_Select_Chart.SelectedItem;
            Chart.Update();
        }
        catch
        {
            foreach(Series x in Chart.Series)
            {
                x.ChartType = SeriesChartType.Line;
                MessageBox.Show("Error generating chart. Default to line.");
            }
        }

但是,try / catch不起作用,它只是抛出异常 . -Throws on Chart.update()

我想知道如何捕获甚至只是检查错误 . 不必砍掉和更改组合框列表会很好 .

任何人都可以解释为什么这个异常没有被try / catch块捕获?
谢谢 .

另外附上的是希望堆栈跟踪(仍然是以前从未使用过的)System.Windows.Forms.DataVisualization.dll!System.Windows.Forms.DataVisualization.Charting.Chart.OnPaint(System.Windows.Forms.PaintEventArgs e) )未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.Control.PaintWithErrorHandling(System.Windows.Forms.PaintEventArgs e,short layer)Unknown未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.Control.WmPaint(ref System.Windows.Forms.Message m)未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m)未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)Unknown未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd,int msg,System.IntPtr wparam,System.IntPtr lparam)未知未加载符号 . [本机到托管转换]带注释的框架[管理到本机转换]带注释的框架System.Windows.Forms.dll!System.Windows.Forms.Control.Update()未知没有加载符号 .

Labassist.exe!Labassist.Frm_Charts.Populate_Chart()404行C#符号已加载 . Labassist.exe!Labassist.Frm_Charts.Cmb_Select_Chart_SelectedIndexChanged(object sender,System.EventArgs e)Line 435 C#符号已加载 . System.Windows.Forms.dll!System.Windows.Forms.ComboBox.OnSelectedIndexChanged(System.EventArgs e)未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.ComboBox.WmReflectCommand(ref System.Windows.Forms.Message m)未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.ComboBox.WndProc(ref System.Windows.Forms.Message m)未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m)未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)Unknown未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd,int msg,System.IntPtr wparam,System.IntPtr lparam)未知未加载符号 . [本机到托管转换]带注释的框架[管理到本机转换]带注释的框架System.Windows.Forms.dll!System.Windows.Forms.Control.SendMessage(int msg,System.IntPtr wparam,System.IntPtr lparam)未知没有符号加载 . System.Windows.Forms.dll!System.Windows.Forms.Control.ReflectMessageInternal(System.IntPtr hWnd,ref System.Windows.Forms.Message m)未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.Control.WmCommand(ref System.Windows.Forms.Message m)未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m)未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.Form.WndProc(ref System.Windows.Forms.Message m)Unknown未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m)未知未加载符号 . System.Windows.Forms.dll中!System.Windows.Forms.Control.ControlNativeWindow.WndProc(REFSystem.Windows.Forms.Message m)未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd,int msg,System.IntPtr wparam,System.IntPtr lparam)未知未加载符号 . [本机到托管转换]带注释的框架[管理到本机转换]带注释的框架System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m)未知没有加载符号 . System.Windows.Forms.dll!System.Windows.Forms.Control.DefWndProc(ref System.Windows.Forms.Message m)未知没有加载符号 . System.Windows.Forms.dll!System.Windows.Forms.Control.WmCommand(ref System.Windows.Forms.Message m)未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.ComboBox.WndProc(ref System.Windows.Forms.Message m)未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m)未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)Unknown未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd,int msg,System.IntPtr wparam,System.IntPtr lparam)未知未加载符号 . [本机到托管转换]带注释的框架[管理到本机转换]带注释的框架System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m)未知没有加载符号 . System.Windows.Forms.dll!System.Windows.Forms.ComboBox.DefChildWndProc(ref System.Windows.Forms.Message m)未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.ComboBox.ChildWndProc(ref System.Windows.Forms.Message m)未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.ComboBox.ComboBoxChildNativeWindow.WndProc(ref System.Windows.Forms.Message m)未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd,int msg,System.IntPtr wparam,System.IntPtr lparam)未知未加载符号 . [本机到托管转换]带注释的框架[管理到本机转换]带注释的框架System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID ,int reason,int pvLoopData)未知未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason,System.Windows.Forms.ApplicationContext context)Unknown未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason,System.Windows.Forms.ApplicationContext context)Unknown未加载符号 . System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm)Unknown未加载符号 . Labassist.exe!Labassist.Program.Main()第20行C#符号已加载 .

谢谢