foreach (Widget item in items)
{
try
{
//do something...
}
catch { }
}
foreach (Widget item in items)
{
try
{
//do something...
}
catch { continue; }
}
foreach (Widget item in items)
{
try
{
//do something...
}
catch { }
}
foreach (Widget item in items)
{
try
{
//do something...
}
catch { continue; }
}
catch { continue; }
会导致代码开始一个新迭代,跳过循环内 catch
块后面的所有代码。
for (int i = 0; i < 10; i++)
{
try
{
throw new Exception();
}
catch
{
}
Console.WriteLine("I'm after the exception");
}
for (int i = 0; i < 10; i++)
{
try
{
throw new Exception();
}
catch
{
continue;
}
Console.WriteLine("this code here is never called");
}
public static void Main(string[] arguments)
{
foreach (int item in new int[] { 1, 2, 3 })
{
try
{
}
catch
{
}
}
foreach (int item in new int[] { 1, 2, 3 })
{
try
{
}
catch
{
}
}
}
catch { continue; }
将跳过catch块后面的任何内容!!!
catch{}
仍将执行catch块后面的语句!!
continue
会被忽略的地方时,你为什么要发表这样的评论。 - ChaosPandion