gray metal cubes decorative

Await in Catch and finally block in C# 6.0

In the earlier versions of C# , there was no provision to have the await keyword in catch and finally block . This was a kind of limitation and developers had to use a workaround to get this to work.

In C# 6.0 , the await can now be used within the the catch and finally block.

Await in Catch and finally block in C# 6.0

WebClient client = null;
try
{
    client = new WebClient();
    string response = await client.DownloadStringTaskAsync(new Uri("http://developerpublish.com"));
    Console.WriteLine(response);
}
catch (Exception e)
{
    // Logging Logic
    await Logger.LogAsync(client, e);
}
finally
{

}

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...