C
C#9mo 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
Omnissiah
Omnissiah9mo ago
have you enabled to catch that exception in visual studio?
olokos
olokosOP9mo 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.
Want results from more Discord servers?
Add your server