正如其他人所述,但专注于异常,这实际上是关于转移控制权的模棱两可的处理。
在您看来,您可能正在考虑这样的情况:
public static object SafeMethod()
{
foreach(var item in list)
{
try
{
try
{
//do something that won't transfer control outside
}
catch
{
//catch everything to not throw exceptions
}
}
finally
{
if (someCondition)
//no exception will be thrown,
//so theoretically this could work
continue;
}
}
return someValue;
}
从理论上讲,您可以跟踪控制流并说“是的”。没有引发异常,没有控制权被转移。但是C#语言设计人员还要考虑其他问题。
被抛出的异常
public static void Exception()
{
try
{
foreach(var item in list)
{
try
{
throw new Exception("What now?");
}
finally
{
continue;
}
}
}
catch
{
//do I get hit?
}
}
可怕的五岛
public static void Goto()
{
foreach(var item in list)
{
try
{
goto pigsfly;
}
finally
{
continue;
}
}
pigsfly:
}
回报
public static object ReturnSomething()
{
foreach(var item in list)
{
try
{
return item;
}
finally
{
continue;
}
}
}
分手
public static void Break()
{
foreach(var item in list)
{
try
{
break;
}
finally
{
continue;
}
}
}
所以在最后,是的,虽然是一个轻微使用的可能性,continue在控制不被转移的情况,但一个很好的协议的情况下(多数?)涉及异常或return块。语言设计人员认为这将太含糊,并且(很可能)无法确保在编译时仅在不传输控制流的情况下continue使用您的语言。