Open gafter opened 4 years ago
This could also affect async iterator methods. We could consider checking VB for alignment.
I just hit this message trying to see if I was missing an exception in an iterator I'm trying to write for some database access. What's needed to implement this? Is it just planning/dev cycles or is there something else that needs to be done?
It'd be easier to wrap my whole method in a try/catch as I have a lot of using statements to capture the database handles and contexts. So, it's a bit hard to try and make repeated try/catch around all the database calls and leave the yield statement inside out of it.
What's needed to implement this? Is it just planning/dev cycles or is there something else that needs to be done?
This issue as marked as Any Time and Needs Implementation. It is open for community contribution, but the dev team is unlikely to implement it ourselves.
@333fred @jcouv @CyrusNajmabadi So, if its open for community contribution, and I want to contribute, where should I start? This feature is quite big, I think I need some kind of approval to be able to work on this from core roslyn team
@MadL1me feel free to come talk to us on discord.gg/csharp in the Roslyn channel, and we can help guide you.
I just hit this message trying to see if I was missing an exception in an iterator I'm trying to write for some database access. What's needed to implement this? Is it just planning/dev cycles or is there something else that needs to be done?
It'd be easier to wrap my whole method in a try/catch as I have a lot of using statements to capture the database handles and contexts. So, it's a bit hard to try and make repeated try/catch around all the database calls and leave the yield statement inside out of it.
I fully agree, I have same issue, I have a very big function with multiple database calls where at the moment I have a try catch of the whole code to catch any exception may occur. Also I have a case where I am calling same function multiple times with different input parameters, a case where there is the need to break but let the other function call to continue and a case where you can cancel the request and then most of the times database throws an exception. This restriction by implementing try catch to every database statement will make the code not easy to understand. Currently I am using SignalR to sent messages into UI and need to switch to AsyncEnumerable as SignalR brings a headache when you want to scale out your application.
Any updated on this topic? There are also other connected topics with this one expressing the demand of this feature.
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.