Defensive programming is a concept in which the programmer attempts to write code while anticipating any errors that could be caused, and has safety measures in advance such as exceptions.