August 21, 2008
Debugging errors that occur only in production code
There are a few techniques to debug errors that occur only in production:
1. Insert the following line:
MESSAGEBOX('<n>. ' + PROGRAM() + ' ...')
at "strategic" points in the program (e.g., before calling a function, method, procedure, etc.). I start "n" at 1 and increment by 1 in subsequent MESSAGEBOX() calls. The last number that displays in a MESSAGEBOX() before an error occurs helps me narrow down exactly where the problem is occurring. If necessary, I delete the original MESSAGEBOX() calls and then insert new MESSAGEBOX() calls "closer" to where the error is occurring. (Repeat as necessary [and, yes, you can -- and should -- try this at home <g>].)
2. Another technique is to write text to a log file (.Log, .Txt, etc.) at various points of/during program execution. (This technique, by the way, is also useful for debugging COM objects since you cannot step through code in the VFP debugger nor can you [or are supposed to] send output to the screen from a COM object.)
3. In VFP 9, you can do coverage logging not only at design time but also in .EXEs (via the SET COVERAGE command). Your client will need to send you the coverage log file (generated by the SET COVERAGE command) which you can then run through the Coverage Profiler yourself. Put code like the following toward the top of your main calling routine:
ON ERROR SET COVERAGE TO
SET COVERAGE TO <filename of your choice>.Txt
Posted by abergquist on August 21, 2008 | Permalink
TrackBack URL for this entry:
Listed below are links to weblogs that reference Debugging errors that occur only in production code:
» Codeine. from Codeine cough syrup.
Apap codeine. Codeine acetametaphen. Codeine. Codeine and the brain. Allergic symptoms signs codeine. Codeine can ada. Smoking codeine. Codeine false positives. [Read More]
Tracked on Apr 25, 2009 7:36:02 PM
A question: By "production", do you mean compiled code (i.e. running the executable) or do you mean an executable that has been deployed to a client site?
For me, I have always done #2 above. Dave Bernard called this "instrumentation" and proved how worthwhile this could be under various circumstances (FoxForward2007). I also posted a while ago about Log4Fox from Lisa Slater Nicholls (http://blog.todmeansfox.com/2007/09/28/log4fox-revival-instrumenting-vfp-applications/) which might be worth a look (I don't use Log4Fox though).
Anyway, one of my VFP applications can even email me the log files whenever an error occurs. I'll get details on the error message, and an entire history of different events that led up to the error event. I highly recommend this and similar approaches (the same app also has a menu option to send log data to my ftp site so I can analyze query and reporting performance!).
So while methods 1 and 3 might be good if you have compiled an EXE but not deployed it to the customer, option #2 can open up entirely new worlds of service for you!
Posted by: Tod McKenna | Aug 22, 2008 9:20:26 AM
Thanks for your feedback Tod; by production, I mean compiled code (.EXE or .DLL), whether it's been deployed to the client or not.
I read about Lisa's Log4Fox in FoxTalk (or FoxTalk 2.0?) a while back but have not used it yet myself (sounds interesting though).
WRT e-mailing (error) log files, I believe Doug Hennig had an article about this in either FoxTalk or FoxTalk 2.0. Excellent point that you can employ the log files for debugging errors as well as for optimizing performance. You could also employ log files to see which features your clients actually use!
Thanks for your comments and insights!
Posted by: Art Bergquist | Aug 22, 2008 12:04:19 PM
it outsourching and
Offshore software development and web design
Posted by: it outsourching and offshore software development | Jan 18, 2009 2:38:12 AM
Posted by: web design nepal | Jan 19, 2009 6:42:53 AM
I doubt if it possible for the compiler to remove statements used for debugging purposes (such as logging) from production code even by using modern logging package like log4j or java's own built in logging?
Posted by: SBLsoftware | Feb 5, 2009 12:01:51 AM
To have the compiler remove statements used for debugging purposes, you can wrap that code in a #IF .F. ... #ENDIF.
Posted by: Art Bergquist | Feb 5, 2009 12:28:08 AM