Even better than good error messages is a careful design which prevents a problem from occurring in the first place:
Minimize the user's memory load by making objects, actions, and options visible. The user should not have to remember information from one part of the dialogue to another:
Level 4 · Principles of Design