Tuesday, November 1, 2011

11 Most Common Mistakes with Error Handling

You wrote a cool script or program.  Awesome.  And then one of your users launches it.  It prompts to enter a date in a text box.  The user enters "Dog".  Your awesome script/program implodes. The user immediately turns to his/her coworkers and proclaims your code is a piece of shit and you suck at writing it.

Is that person wrong?

11 Most Common Mistakes with Error Handling
  1. Forgetting to handle errors
  2. Not checking data types
  3. Not checking formatting ("8005551212" or "800-555-1212" or "(800) 555-1212", etc.)
  4. Not checking/correcting string case where case matters ("Foo", "foo", or "FOO"?)
  5. Not trimming string input before Boolean operations (does "FOO " = "FOO" ?)
  6. Not controlling the UI (checkbox, radio buttons, lists, instead of text boxes)
  7. Not checking for specific error type following an exception
  8. Building error PREVENTION into the UI
  9. Documenting your code (especially in places where exceptions are most likely to occur)
  10. Using outdated error handling (if your language supports Try/Catch/Fail, etc. use it!)
  11. Forgetting to manage exit codes (raising errors)
The answer to the question above is "No", but they should still be smacked in the face just for being obnoxious.
Post a Comment