Throwing exception vs checking null, for a null argument

Posted by dotnetdev on Stack Overflow See other posts from Stack Overflow or by dotnetdev
Published on 2010-03-26T21:53:46Z Indexed on 2010/03/26 22:03 UTC
Read the original article Hit count: 601

Filed under:
|
|

What factors dictate throwing an exception if argument is null (eg if (a is null) throw new ArgumentNullException() ), as opposed to checking the argument if it is null beforehand.

I don't see why the exception should be thrown rather than checking for null in the first place? What benefit is there in the throw exception approach?

This is for C#/.NET

Thanks

© Stack Overflow or respective owner

Related posts about ADO.NET

Related posts about exception