更新:2007 年 11 月

错误消息

无法在 catch 子句体内生成值

不允许从 catch 子句体内使用 yield 语句。若要避免此错误,请将 yield 语句移到 catch 子句体的外面。

下面的示例生成 CS1631:

 复制代码
// CS1631.cs
using System;
using System.Collections;

public class C : IEnumerable
{
   public IEnumerator GetEnumerator() 
   {
      try
      {
      }
      catch(Exception e)
      {
        yield return this;  // CS1631
      }
   }  

   public static void Main() 
   {
   }
}