csharplang icon indicating copy to clipboard operation
csharplang copied to clipboard

[Proposal]: Remove error "Cannot yield a value in the body of a try block with a catch clause"

Open 333fred opened this issue 11 months ago • 0 comments

Remove error "Cannot yield a value in the body of a try block with a catch clause"

  • Specification: https://github.com/dotnet/csharplang/pull/8413
  • Discussion: https://github.com/dotnet/csharplang/discussions/8994

Summary

As recently noted by C# users, the existing restriction that you cannot yield a value in the body of a try block with a catch clause is one that interferes with reasonable code refactoring. The restriction does not make the compiler any easier. Rather it was added to align with the conceptual model that the caller's loop is logically "called" at the point of the yield. But that is not how people think of the construct, and the restriction has little value. We propose to remove it.

Design meetings

333fred avatar Jan 06 '25 22:01 333fred