In a production system, error-checking and logging are not optional activities. They are an essential component of its health and continued operation. In a way, they go hand-in-hand.
Error-checking should be done on every single untrusted value that enters a sub-routine. Every check that fails should log an error. Potentially, an error should be thrown, possibly even a fatal one.
An untrusted value is one that comes from a source that is not a subroutine you wrote yourself. A non-exhaustive list would include:
What if there is no space on the drive? The program will crash the first time HANDLE is written to, cause it wasn't opened successfully.open HANDLE, ">myfile";
As for logging ... it's usually the only way you know what your program has done. When I write something, it spews out tons of crap onto the screen. 99% of it, I will never use. 99% of the time, I won't use the other 1%. That 1% of the time ... My! how that 1% of the logging has saved me days of work. (No exagerration!)
Newer programmers seem to have this idea that logging and error-checking are both a waste of time. On the contrary, they are the greatest time-saving tools we as programmers have! Ask any person who's been programming for more than five years. Heck, even hackers do it. :-)
Update: Added databases to the listed of untrusted sources as per scain. Thanx!
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Error-checking and logging
by mirod (Canon) on Feb 26, 2002 at 16:46 UTC | |
by dragonchild (Archbishop) on Feb 26, 2002 at 16:55 UTC | |
by grep (Monsignor) on Feb 26, 2002 at 18:13 UTC | |
|
•Re: Error-checking and logging
by merlyn (Sage) on Feb 26, 2002 at 16:01 UTC | |
by tilly (Archbishop) on Feb 26, 2002 at 19:14 UTC | |
by premchai21 (Curate) on Feb 27, 2002 at 00:13 UTC | |
by tilly (Archbishop) on Feb 27, 2002 at 00:35 UTC | |
|
Re: Error-checking and logging
by scain (Curate) on Feb 26, 2002 at 20:26 UTC |