开发者

Why does this error not get caught?

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 deleteSelect开发者_开发百科or, 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜