In my application i inherited some code and i see this construct;
string? content = null;
try
{
content = await result.Content.ReadAsStringAsync(cancellationToken);
}
catch(Exception e) when (e is not OperationCanceledException)
{
// Swallow
}
Is this superfluous? Can ReadAsStringAsync
throw anything other than OperationCancelledException
or can the catch be removed assuming the OperationCancelledException
is caught up the chain?
The msdn docs do not show any exceptions other than OperationCancelledException
.
https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent.readasstringasync?view=net-8.0