跳过异常(超出索引),程序在捕获后挂起 [英] Skip a Exception (out of index), program hangs after catch
本文介绍了跳过异常(超出索引),程序在捕获后挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的承诺在捕获之后出现错误并且不再运行。
任何人都知道如何跳过索引?没试过; catch?
my promgram bugs after the catch and won't run anymore.
anyone know how to skip a out of index? without try; catch?
try
{
lines2 = ResultViewshown2[i].Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
for (int x = 0; x < 10000; x++)
{
string line = lines2[x];
if (!line.Contains(check2))
{
Resultadd2.Add((string.Format("{0}\r\n", line ?? string.Empty)));
}
}
}
catch(IndexOutOfRangeException)
{
}
推荐答案
我会遵循更多的防御方法。见下文:
I would be following more defensive approach. See below:
try
{
lines2 = ResultViewshown2[i].Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
for (int x = 0; x < lines2.length; x++)
{
string line = lines2[x];
if(!string.IsNullOrEmpty(line))
{
if (!line.Contains(check2))
{
Resultadd2.Add((string.Format("{0}\r\n", line ?? string.Empty)));
}
}
}
}
catch(IndexOutOfRangeException)
{
//handle your exception
}
这篇关于跳过异常(超出索引),程序在捕获后挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文