visual c#.net中的错误 [英] error in visual c#.net

查看:56
本文介绍了visual c#.net中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写这个鳕鱼



for int(I = 0 I< 100)

{

}



in I [50] i ive错误我希望app不要停下来然后去[51]。但程序停止并显示捕获信息

{

}

解决方案就像vb6中的简历。

抱歉英语不好。

I write this cod

for int(I= 0 I<100)
{
}

in I[50] ihave error I want app don't stop and go I[51].but program stop and show message in catch
{
}
solution like resume next in vb6.
sorry for bad English.

推荐答案

好的,所以把Try / Catch块放在循环中,而不是放在外面。
OK, so put the Try/Catch block inside the loop, not outside.


据我所知,你的问题可能存在以下2个概率:



1.在迭代for循环时,一旦达到i = 50,你就会得到一些未处理的异常并使你的应用程序崩溃。

在这种情况下,最好的办法是找出你获得该例外的原因。查看异常消息和堆栈跟踪会很有帮助。如果你无法阻止异常被引发,你必须将你的代码包含在try catch中,如下所示:



As far as I could understand your question, following 2 probabilities could exist:

1. While iterating in for loop, as soon as you reach i = 50 you get some exceptions that remains unhandled and crashes your application.
In this case best thing is to find out why you are getting that exception. Looking at exception message, and stack trace would be helpful. If at all you can't stop the exception from being raised, you must enclose your code in try catch as below:

for(i=0; i<100;i++)
{

try{

//...your code goes here
}

catch(Exception ex) //Better to replace Exception with exact type of exception that you are getting
{
//Log or handle the exception scenario....
}
}







2.如果您已将I声明为某个阵列,并且您在我[50]中遇到错误,然后很可能我的长度限制在50(除非你已经编写了自己的索引器,在你的情况下有在我看来,概率最低)。

所以你不能得到第51个元素。



请确认您的异常是索引超出范围。



在这种情况下,如果你想获得100个元素,那么你可以这样写:






2. If you have declared I as some array and if you are getting error in I[50] , then most probably length of I is limited to 50 (until and unless you have written your own indexer, which in your case has lowest probability in my opinion).
So you can not get 51st element.

Please confirm that you are getting exception that says something like "Index out of range".

In this case if you want to get to 100 elements then you write something like:

int I =new int[100]





然后迭代我。



and then iterate on I.


这篇关于visual c#.net中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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