The
defensive programming principles state that we should
validate and
assert the preconditions (input parameters, return values of called methods, current system state) before executing the particular method code. The obvious benefit of this approach is it allows you to catch bugs early and to get a reasonable stacktrace that limits the scope for finding the error in the code.