3 ms·
> That is a small nicety. As I read it, it's more than that - you get to see the expression passed as an argument. If they would bake in that expression withi
by jve 5y ago
> That is a small nicety.
As I read it, it's more than that - you get to see the expression passed as an argument.
If they would bake in that expression within NullReferenceException, well that would be so good... because there are methods that contain dozens of lines and that particular exception can happen almost anywhere. Usually I'm considering that when writing code and thinking: well this method can't throw NullReferenceException, just to be greeted with that particular exception at runtime, ugh.
- jmull 5y ago> If they would bake in that expression within NullReferenceException, well that would be so good... CallerArgumentExpression doesn't do that, though. I think you could maybe use it to do something explicit, like... someexpr.CheckNotNull().DoSomethingWithSomeExpr() where CheckNotNull() somehow uses CallerArgumentExpression to capture "someexpr" so that if someexpr was null, the exception could include the actual expression in the exception message. But that means decorating code with CheckNotNull() all over the place, which really limits this. What you really want here is a good call stack -- maybe with expressions, source lines, local variable values, etc.