Joy of Programming: Abort, Retry, Fail?

1
224
Errors everywhere you go!

Errors everywhere you go!

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.
But what is the error?

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.
Did you check for syntax errors?

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”.
How is this error message supposed to help anyone?

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.
Aren't you contradicting yourself with that message?

Guideline 5

Don’t try humour. If yours is a “critical” application, your user will not laugh when an exceptional situation occurs!
There's a time and place for humour!

Feature image courtesy: Nick J Webb. Reused under the terms of CC-BY 2.0 License.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here