What is the correct way of rewriting the code in the following catch block using a conditional expression? if supported!?
try
{
return await _client.GetStreamAsync(_uri);
}
catch
{
if (IsConnected)
throw;
else
throw new IOException();
}
C# compiler does not like the following
IsConnected ? throw : new IOException();
Note that re-throwing a caught exception, like the following, is in violation of CA2200
try
{
return await _client.GetStreamAsync(_uri);
}
catch (Exception ex)
{
throw IsConnected ? throw ex : new IOException();
}