HomeCSharpAwait in Catch and finally block in C# 6.0

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

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...