Monday, 19 October 2015

ASP.NET Tips #35 - Use defensive coding techniques such as performing null checks wherever applicable to avoid NullReferenceExceptions at runtime

Exceptions can be slow and should only be used in exceptional circumstances, rather than for general control flow. Instead of assuming an object will not be null at runtime, utilize defensive coding to ensure your code only acts on objects that are not null. This will assist performance by throwing fewer exceptions, and ensure a more robust and reliable application.

For example, consider the Tester-Doer pattern explained here: https://msdn.microsoft.com/en-us/library/vstudio/ms229009(v=vs.100).aspx

No comments :

Post a comment