★throw式が記述できる箇所は以下の3か所
1:ラムダ式、式形式メンバーの「=>」の右辺
2:Null合体演算子(??)の右辺
3:条件演算子の2,3つ目の引数
上記以外での記述はコンパイルエラーとなる。
throw式記述場所
//1:ラムダor式形式のメンバーの中
static void test1() => throw new NotImplementeException();
static string test2(string ex)
{
//2:Null合体演算子(??)の右辺
var a = ex as string ?? throw new ArgumentException(nameof(obj));
//3:条件演算子の2,3つ目の引数
return a.Length == 0 ? "enmpty" :
a.Length < 5 ? "short" :
throw new InvalidOperationException("too long");
}