Error Handling

To paraphrase a well-known saying, "To error is human, to forgive is just good programming!". Every user whether maliciously or accidentally will provide bad input at some time. This is a fact of life we must live with as programmers. However, the bright spot of this problem is we control when the user can give us this bad input. We know the time and place when all input must occur and we hopefully know the format of the desired input; therefore, we must take responsibility for ensuring bad input does not propagate through the program. Error trapping procedures must always be agreed upon in advance between the programmer and the user or user representative and be well documented. At no time is it acceptable for an user input to unexpectedly terminate your program!

So what do you do protect yourself against bad input? The answer is simple, after any input you must first check the validity of the input before proceeding and then decide how to respond to bad input.

  1. Validity Checking
  2. Responses - different languages provide different programming constructs to trap errors but the net effect should always be the same.