C#C
C#2y ago
olokos

C# .NET - cannot catch HttpRequestException in any way possible. Please help.

try
{
    checkingResponse = await client.GetAsync(websiteUrl);
}
catch (HttpRequestException e)
{
    Console.WriteLine($"{websiteUrl} - HttpRequestException occurred: {e.Message}");
}
catch (Exception ex)
{
    Console.WriteLine($"{websiteUrl} - Unexpected error occurred: {ex.Message}");
}


I have written this very simple code, but for some reason, each time it crashes in Debug mode, I'm getting HttpRequestException despite my attempts to catch it.

What's wrong here, why I cannot actually catch this exception?
image.png
Was this page helpful?