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(); }
ifversion? Im pretty sure the ternary is not legal C#; ternaries are expressions, not statementsifin the first example? if so, no, that works fine.throw someExceptionis legal in a ternary, butthrowis not, this is from C#7 stackoverflow.com/questions/42209135/…