« Make use of methods for complex Dynamic... grid settings | Main | When a "Watch Window" expression goes in and out of scope »
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
TrackBack URL for this entry:
http://www.typepad.com/t/trackback/384091/32626202
Listed below are links to weblogs that reference Debugging errors that occur only in production code:
Comments
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!
Great topic!
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




