Skip to content

Instantly share code, notes, and snippets.

@txdv
Last active February 15, 2017 18:14
Show Gist options
  • Save txdv/5f825fdc5b2d2e13680e3667472a6ee5 to your computer and use it in GitHub Desktop.
Save txdv/5f825fdc5b2d2e13680e3667472a6ee5 to your computer and use it in GitHub Desktop.
Can not yield from finally block
using System;
using System.Collections.Generic;
public class MainClass
{
public static IEnumerable<string> Actions()
{
try {
yield return "try";
} catch (Exception) {
yield return "catch";
// exceptions.cs(11,4): error CS1631: Cannot yield a value in the body of a catch clause
} finally {
yield return "finally";
// exceptions.cs(14,4): error CS1625: Cannot yield in the body of a finally clause
}
}
public static void Main(string[] args)
{
foreach (var v in Actions()) {
Console.WriteLine(v);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment