Provide Necessary Error Messages

While it is important not to give unnecessary error messages, it is equally important to give necessary error messages. This might seem incredibly obvious, but not reporting errors with error messages is an easy trap for programmers to fall into. Assertions and TRACE statements are largely to blame. Perhaps you've seen code that looks like this:

 if (!SaveFile(filename,…))    TRACE("Can't save file"); 

Now suppose that this code is in a text editor and an error occurs while the user is saving a file. Since no error message is provided, the user will assume the file was saved, only to find out later—the hard way—that the information has been lost. I know—you would never do such a thing. Maybe so, but other programmers do, since I see code like this all the time.

Regarding the TRACE statement itself, the most important thing to understand with this example is that this use of a TRACE statement is totally inappropriate. You should use assertions and TRACE statements only to help you debug and to report erroneous execution. Erroneous execution is the result of a bug in your program. The inability to save a file isn't a bug; it is abnormal execution, which is the result of a situation beyond the program's control. Any abnormal execution that cannot be handled by the program requires an error message.

Assertions and TRACE statements are not error messages and should never be used as a substitute.

TIP
Never use assertions or TRACE statements as a substitute for error messages.



Developing User Interfaces for Microsoft Windows
Developing User Interfaces for Microsoft Windows
ISBN: 0735605866
EAN: 2147483647
Year: 2005
Pages: 334

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net