为什么这个错误没有被抓住? [英] Why does this error not get caught?

查看:111
本文介绍了为什么这个错误没有被抓住?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有以下代码,deleteselector是一个具有datagridview(带有自动调整列)的表单。

  try 
{
if(deleteSelector.ShowDialog()== DialogResult.OK)
{
}
}
catch(InvalidOperationException)
{
// Bug解决方法
}
/ pre>

try catch是因为一个具有gridview的弹出窗体会在一段时间内抛出一个invalidoperationexception。这是建议的解决方法,请参阅



http://connect.microsoft.com/VisualStudio/feedback/details/145633/ invalidobject-throw-when-a-form-with-a-bound-datagridview-with-auto-sizing-columns-is-shown



我在deleteSelector上使用Show,解决方法工作完美。现在,使用showdialog,似乎错误不再被捕获(我收到一个未捕获的错误消息)。为什么错误没有被捕获?

解决方案

ShowDialog 运行对话框一个单独的线程,所以异常被抛在一个不同的堆栈到你的异常处理程序。



我建议你尝试找到一个不同的解决方法 - 只是捕捉 InvalidOperationException 是非常可怕的,我不想打赌,这种形式将会在一个明智的状态之后。


I have the following code in my project, deleteselector is a form that has a datagridview (with autosize columns) on it.

try
{
      if (deleteSelector.ShowDialog() == DialogResult.OK)
      {
      }
}
catch (InvalidOperationException)
{
   //Bug workaround
}

The try catch is because a pop-up form with a gridview on it trows a invalidoperationexception once in a while. This is the suggested workaround, see

http://connect.microsoft.com/VisualStudio/feedback/details/145633/invalidoperationexception-thrown-when-a-form-with-a-bound-datagridview-with-auto-sizing-columns-is-shown

Earlier, I used Show on the deleteSelector, and the workaround worked perfectly. Now, with showdialog it seems that the error is not catched anymore (I get an uncatched error message). Why is the error not catched?

解决方案

ShowDialog runs the dialog on a separate thread, so the exception is being thrown in a different stack to your exception handler.

I suggest you try to find a different workaround - just catching InvalidOperationException is pretty horrible, and I wouldn't like to bet that the form would be in a sensible state afterwards.

这篇关于为什么这个错误没有被抓住?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆