Saw kind of this code in production:
var task = new HttpClient().GetAsync(u);
var response = await task;
if (task.IsCompletedSuccessfully)
{
Console.WriteLine($"Task is faulted: {task}");
}
Question: Does it make any sense to check the Task state after the await
keyword? As far as I know, the compiler will build a state-machine "around" this code, which throws an exception in case of an error. Based on that it won't make any sense to check the Tasks state.
Am I missing something?
Thanks