Check arguments before actual code
Fail method execution as soon as possible. Write argument checks in the method start. Always use adequate exception classes: java.lang.IllegalArgumentException in Java and System.ArgumentException in C#. Pay more attention to the public methods that will be used by other programmers with high probability. The same rule applies to state checks. For example, throw an exception before any real logic execution if your object is disposed. Try to avoid manual security-related checks, use declarative security. Use System.ArgumentNullException instead of System.NullReferenceException if required argument is null. Design
|