C
C#3mo 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}");
}
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?
No description
2 Replies
WEIRD FLEX
WEIRD FLEX3mo ago
have you enabled to catch that exception in visual studio?
olokos
olokos3mo ago
That's right, I did at some point! I've unticked the "stop on this exception", right below the break in IDE and now it works properly. Really odd that breaking on the exception and then pressing continue made the app crash completely.