Visual Studio中的新异常 [英] New exceptions in Visual Studio

查看:71
本文介绍了Visual Studio中的新异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Net Framework 4在SharpDevelop中创建一个c#winform应用程序。应用程序几乎完成但我决定使用Visual Studio 13 Community Edition。当我通过Visual Studio运行应用程序时,它给了我奇怪的异常(当我删除Datagridview中的某些行时RowNotInTableException)。我再次在SharpDevelop中运行应用程序,没有例外。



我的问题是,这些来自Visual Studio的新异常是否存在于我的代码中,现在Visual Studio正在发现这些异常。我现在该如何修复它们?



现在我无法在Visual Studio中再次检查我的完整应用程序以查看是否有新的异常? />


编辑1:



我有一个datagridview,datatable(dt)和一个bindingsource(bs)。



bs.DataSource = dt;

dataGridView1.DataSource = bs;



现在,如果我在正在运行的应用程序中的datagridview中添加一些数据,然后通过单击行标题选择整行,然后按键盘上的删除键。它在以下代码中给出了例外。



例外是:



类型系统的例外情况.Data.RowNotInTableException在System.Data.dll中发生但未在用户代码中处理



附加信息:此行已从表中删除但没有任何内容数据。 BeginEdit()将允许在此行中创建新数据。





I was making a c# winform application in SharpDevelop using Net Framework 4. The application is almost complete but I decided to use Visual Studio 13 Community Edition. When I run application in this through Visual Studio, It is giving me strange exception (RowNotInTableException when I delete some row in Datagridview). I again run the application in SharpDevelop and there was no exception.

My question is, are these new exceptions from Visual Studio or already existed in my code which are now being discovered by Visual Studio. and how can I fix them now???

Now I cannot check my complete application again in Visual Studio to see whether there are new exceptions or not??

Edit 1:

I have a datagridview, datatable (dt) and a bindingsource (bs).

bs.DataSource = dt;
dataGridView1.DataSource = bs;

Now if I add some data in datagridview in the running application and then select the entire row by clicking the row header and then press "delete key" on keyboard. It gives me exception in the following code.

The exception is:

An exception of type System.Data.RowNotInTableException occurred in System.Data.dll but was not handled in user code

Additional information: This row has been removed from a table and does not have any data. BeginEdit() will allow creation of new data in this row.


dataGridView1.DataBindingComplete += (S,E)=>
            {
                for(int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["order Ref No."].ToString() != "")//Exception occurs here
                    {
                        //do something
                    }
                }

            };

推荐答案

不同框架的效果不取决于实际安装的框架,而是取决于正在执行的程序集的目标框架



假设您开发了一些具有.NET v.4.0的产品。显然,所有程序集都针对v.4.0或更低版本。当您的用户安装v.4.5或4.6时,不应更改任何内容。即使某些用户没有任何.NET版本,也会支持安装v.4.0。没有什么不好的东西应该改变。



现在,如果只有v.4.5或4.6发布的问题,它不会成为不修复代码的借口。实际上,这听起来很奇怪,我不能100%确定你的观察是正确的,但让我们假设情况确实如此。如果发现某些问题但它不会影响您产品的某些版本,那么它仍然是一个应该修复的问题。你打算支持你的产品,不是吗? :-)



-SA
The effect of different framework depends not on the actually installed framework(s), but on the target framework of the assemblies being executed.

Suppose you develop some product having .NET v.4.0. Apparently, all the assemblies are targeted to v.4.0 or lower versions. When your user installs v.4.5 or 4.6, nothing should be changed. Even if some user does not have any .NET version and installs v.4.0 will be supported. Nothing bad should be changed.

Now, it won't be the excuse for not fixing your code, if there is some issue revealed only by v.4.5 or 4.6. Actually, it sounds weird, and I cannot be 100% sure your observations are correct, but let's assume it is really the case. If some problem is revealed but it does not affect some version of your product, it's still a problem which should be fixed. You are going to support your product, aren't you? :-)

—SA


通过添加
dt.AcceptChanges()

如下:



as below:

dataGridView1.DataBindingComplete += (S,E)=>
            {
                dt.AcceptChanges();
                for(int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["order Ref No."].ToString() != "")//Exception occurs here
                    {
                        //do something
                    }
                }
 
            };







但为什么在SharpDevelop IDE中没有引发异常?我猜Visual Studio更好,因为它显示了代码中的所有错误或异常,而SharpDevelop错过了一些。




But why no exception was being raised in SharpDevelop IDE??? I guess Visual Studio is better as it shows all the errors or exception in our code while SharpDevelop misses some.


这篇关于Visual Studio中的新异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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