何かにnullを割り当てようとした場合にスローしたいとします。このトリックについてはどうでしょうか?
public static class ExceptionExtension
{
public static T Throw<T>(this Exception exc)
{
throw exc;
}
}
たとえば、次のように使用できます。
return possibleNull ?? new Exception("Unspecified something....").Throw<string>();
あなたはそれが良い/悪い/役に立たない習慣だと思いますか?