Re: Error Handling
- Posted by Irv Mullins <irvm at ellijay.com> Mar 17, 2001
- 652 views
From: Robert Craig <rds at RapidEuphoria.com> > > What you are asking for now, is a full-blown > exception handling mechanism. That might be > worth doing, I'm not sure. I don't think it is the kind > of panacea for all our programming sins that you and others > are suggesting. In most cases when an error occurs > in a program, that program is skating on very thin > ice, and there is not much that you can do, or should do, > other than shut it down and get as much diagnostic > information as you can get. Soldiering on in the face > subscript violations, uninitialized variables etc, would > allow, in some cases, a program to complete > a logical "transaction", saving user data from > memory to disk, but in other cases it would allow > an incorrect "transaction" to be completed. > Undoing incorrect transactions is often more > difficult than re-doing transactions that were never > completed. There's a certain elegance that could result from implementing type() properly. Since type() checks upon each and every assignment, that means you only have to declare a handler once for each class of variable you want to monitor, and your work is done, Wherever you declare an instance of that variable type, the checking and recovery routines are automatically in place. The alternative is to call a function with each and every assignment: x = CheckValidHours(y) -- for an assignment. x = CheckValidHours(get_number(work_hours)) -- for input The problem with this is obvious; code bloat. It gets messy very quickly, whereas, if type() operated as it should, this would be simple and automatic. x = get_number(work_hours) Remember, once our programs are debugged, we are still at the mercy of whoever is _using_ the program! Writing reams of code to check for every conceivable input error and subsequent math error that might result from various unexpected combinations of that input is neither elegant or efficient. There should be an easier way. Regards, Irv