❔ Reading file (.txt)

There is a static function that returns IEnumerable<int> of a file.

Each line of that file has a number. So for each number I'm returning a yield return.

But there's a problem, I want to use a try/catch block. But it doesn't compile: "Cannot yield a value in the body of a try block with a catch clause"

So how can I catch an exception without the catch here? (this finally empty looks really ugly) and why I can't use yield return inside catch? :(
Screenshot_from_2023-09-02_22-10-03.png
Was this page helpful?