I've just noticed that when using throw with the null-coalescing operator, you cannot just use the keyword "throw" on its own, an exception must be included with it. The following code demonstrates what I mean:
try
{
return GetName();
}
catch (NameNotFoundException ex)
{
string name = GetOtherName();
// this is legal
return name ?? throw ex;
// whereas this is not
return name ?? throw;
}
Is there any reason for this? Would it be because throw; doesn't constitute an expression, or is there more to it?