Await in Catch and Finally blocks is a part of C# 6.0
public static async Task<string> Test()
{
await logMethodEntrance();
var client = new System.Net.Http.HttpClient();
var streamTask = client.GetStringAsync("https://localHost:1234");
try
{
var responseText = await streamTask;
return responseText;
}
catch (System.Net.Http.HttpRequestException e) when (e.Message.Contains("401"))
{
await logError("test your accessbility", e);
return "not applicable";
}
finally
{
await logMethodExit();
client.Dispose();
}
}
private static Task logError(string v, HttpRequestException e)
{
throw new NotImplementedException();
}
private static Task logMethodExit()
{
throw new NotImplementedException();
}
private static Task logMethodEntrance()
{
throw new NotImplementedException();
}
public static async Task<string> Test()
{
await logMethodEntrance();
var client = new System.Net.Http.HttpClient();
var streamTask = client.GetStringAsync("https://localHost:1234");
try
{
var responseText = await streamTask;
return responseText;
}
catch (System.Net.Http.HttpRequestException e) when (e.Message.Contains("401"))
{
await logError("test your accessbility", e);
return "not applicable";
}
finally
{
await logMethodExit();
client.Dispose();
}
}
private static Task logError(string v, HttpRequestException e)
{
throw new NotImplementedException();
}
private static Task logMethodExit()
{
throw new NotImplementedException();
}
private static Task logMethodEntrance()
{
throw new NotImplementedException();
}
No comments:
Post a Comment