Type narrowing with the when catch syntax only seems to be picked up correctly if the clause is relatively simple, for example:
public class Foo
{
public async Task BarAsync()
{
HttpClient httpClient = new();
HttpRequestMessage message = new();
try
{
await httpClient.SendAsync(message);
}
catch (Exception e) when (e is HttpRequestException)
{
// Do something.
}
}
}
This correctly detects that HttpRequestException from SendAsync is handled. However:
public class Foo
{
public async Task BarAsync()
{
HttpClient httpClient = new();
HttpRequestMessage message = new();
try
{
await httpClient.SendAsync(message);
}
catch (Exception e) when (e is HttpRequestException or JsonException)
{
// Do something.
}
}
}
This reports 'BarAsync()' may throw undocumented exception: HttpRequestException. Perhaps not all the types in the or block are scanned?
Type narrowing with the
whencatch syntax only seems to be picked up correctly if the clause is relatively simple, for example:This correctly detects that
HttpRequestExceptionfromSendAsyncis handled. However:This reports
'BarAsync()' may throw undocumented exception: HttpRequestException. Perhaps not all the types in theorblock are scanned?