C#C
C#3y ago
oe

❔ C# Exceptions Not Caught?

Why is this code causing Visual Studio to break if it is being ran in a try catch?

It takes me here and shows me this exception:

System.Net.Http.HttpRequestException: 'The proxy tunnel request to proxy '' failed with status code '502'."'

C:\Users\FRZ\AppData\Local\SourceServer\89eb5aeb9b5e4245c273d7fede24aa2abe75483baa9ebc06da5a3ca0b1aba702\src\libraries\System.Private.CoreLib\src\System\Threading\Tasks\ValueTask.cs

[DebuggerBrowsable(DebuggerBrowsableState.Never)] // prevent debugger evaluation from invalidating an underling IValueTaskSource<T>
        public TResult Result
        {
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            get
            {
                object? obj = _obj;
                Debug.Assert(obj == null || obj is Task<TResult> || obj is IValueTaskSource<TResult>);

                if (obj == null)
                {
                    return _result!;
                }

                if (obj is Task<TResult> t)
                {
                    TaskAwaiter.ValidateEnd(t);
                    return t.ResultOnSuccess;
                }

                return Unsafe.As<IValueTaskSource<TResult>>(obj).GetResult(_token);
            }
        }


The issue is occuring here: HttpResponseMessage httpResp = await Client.SendAsync(httpReq);

public static async Task<string?> GetShopHtml(string shopUrl)
    {
        using var httpReq = new HttpRequestMessage(HttpMethod.Get, shopUrl);

        HttpResponseMessage httpResp = await Client.SendAsync(httpReq);


{
    string shopHtml = await TestRequests.GetShopHtml(shopUrl);
    collection = _scanner.ExtractNodes(shopHtml!);
}
catch (Exception ex)
{
    _logger.LogError($"Error while scraping {shopUrl}, added to errors json file.");
    await File.AppendAllTextAsync("Errors.json", ex.ToString());
}


Regardless of the exception type, it should not be breaking in Visual Studio? I am running Visual Studio 2022 preview version
Was this page helpful?