Yield return from a try/catch block [duplicate]
问题 This question already has answers here : yield return with try catch, how can i solve it (10 answers) Closed 6 years ago . As Eric Lippert described in this article, yield return is not allowed within try/catch clauses. Is there a nice way I could get something like this, without having to write my own IEnumerator by hand: public IEnumerable<Data> GetData() { var transaction = Session.BeginTransaction()); try { IQuery q = CreateQuery(session); foreach (var result in q.Enumerable()) yield