Why does this error not get caught?

廉价感情. 提交于 2019-12-08 03:30:53

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/3733948/why-does-this-error-not-get-caught

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!