【问题标题】:C# ListBox_SelectedIndexChanged is like try-catchC# ListBox_SelectedIndexChanged 就像 try-catch
【发布时间】:2013-05-02 21:26:26
【问题描述】:

ListBox_SelectedIndexChanged出现异常时,程序跳出方法,就像我在try-catch块中写代码一样。

这是一个例子:

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    int x = int.Parse("test"); //this should crash the program
}

这很好用,在这种情况下它会导致程序崩溃

private void listBox1_Click(object sender, EventArgs e)
{
    int x = int.Parse("test");
}

只有当我在 VS 中运行程序时才会发生这种情况。当我从资源管理器中运行它时,它每次都会崩溃。

你知道为什么吗?

【问题讨论】:

  • 也许第一个方法没有被调用?你确定你已经连接了事件吗?
  • 你能给我们更多的代码吗?例如:你如何填充你的列表框,你是否在做其他事情,因为如果我只是运行它,它根本不会崩溃。

标签: c# windows forms listbox selectedindexchanged


【解决方案1】:

您是否启用了异常停止?有关异常列表以及何时调用调试器,请参阅 Debug -> Exceptions。您可以让调试器在抛出异常时停止或仅在未处理异常时停止(或两者兼而有之)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-15
    • 1970-01-01
    • 2019-03-02
    • 2011-10-26
    • 1970-01-01
    • 1970-01-01
    • 2011-03-22
    相关资源
    最近更新 更多