Exception handling is tricky to get right. In this column, I present some guidelines for writing good exception handling code, by giving real-world (counter) examples.
Guideline 1
Write descriptive error messages.
Guideline 2
Check for syntax errors before shipping! If your application is written in an interpreted language or a scripting language, your users can end up getting syntax errors if you don’t test it well.
Guideline 3
Write helpful error messages. In the following example, what exactly is the difference between “Abort” and “Fail”? Also, it is better to specify what needs to be done to recover from the situation — for example, “Insert disk” instead of “Retry”.
Guideline 4
Don’t contradict yourself. When throwing an error back to the user, the description should support why an exception happened, not contradict it.
Guideline 5
Don’t try humour. If yours is a “critical” application, your user will not laugh when an exceptional situation occurs!
Feature image courtesy: Nick J Webb. Reused under the terms of CC-BY 2.0 License.
lol i love the “Update Wizard” one. That’s just Window$ being Window$.