Prior to C# 6.0, it was not possible to call async operations in catch {} and finally {} blocks by specifying the await keyword due to implementation specific issues in the C# compiler. But now Microsoft engineers made this impossible task possible by changing their codes in the compiler part. Now you will be able to call the await statements in catch {} and finally {} blocks without writing any complicated code. The compiler will automatically handle it.
Here is a code snippet to show you how easily you can call the await for async operations in catch {} and finally {} blocks. Most of the time we need this to log exceptions and/or do some final clean-ups of the resources.
This feature was in the list of much demanded features by the developers as they had to write some complicated logic in order to implement the same in their code as a workaround. This was due to C# compiler limitations in those days. But now, if you are using C# 6.0, this limitation is gone. Use it whenever you need.
How much did you like the feature and how much will you use it in coming projects when you start using C# 6.0? Do let us know in the below comment section.
Don’t forget to subscribe to my blog’s RSS feed and Email Newsletter to get the immediate updates directly delivered to your inbox. I am available on Twitter, Facebook, Google+ and LinkedIn. Do connect with me there and get the updates that I share over those social networking sites.
nice Article Ajay Sir.
ReplyDelete