Errors Eating My TEXTMERGE
A few days ago I decided to refactor a 6-year old data integration program I wrote in VFP7 (or was it VFP6?) that moves data from a legacy tax system to an operational data warehouse for reporting (SQL Server). The program was self-contained (could be run as a compiled exe from the command line or through the IDE). To make a long story short, I decided to up the code to VFP9 and add some TRY/CATCH statements and additional parameter checking.
The code in this program makes heavy use of TEXTMERGE, utilizing the “\” and “\\” commands.
I wrote a few test cases to exercise my new error handling. What I discovered was that some of my logging stopped working after I added a few TRY…CATCH blocks. Hugh? Here’s a sample:
SET TEXTMERGE ON SET TEXTMERGE TO test ADDITIVE NOSHOW \hello TRY USE xxx CATCH TO oErr \Error: <<oErr.Message>> ENDTRY \world SET TEXTMERGE TO MODIFY FILE test.txt
If you run the above, you only see “hello” printed in the file test.txt:
hello
I went back to my original code without any TRY/CATCH blocks and to my surprise, got the same result. Only ‘hello’ printed. But WAIT… I’m running in VFP9 SP1.
When I run the original code in VFP7:
ON ERROR \Error: <<MESSAGE()>> SET TEXTMERGE ON SET TEXTMERGE TO test ADDITIVE NOSHOW \hello USE xxx \world SET TEXTMERGE TO ON ERROR MODIFY FILE test.txt
I get the expected output:
hello Error: 'xxx.dbf' does not exist. world
It appears as if program errors are killing my TEXTMERGE in VFP9 SP1. I’ll have to try this out on my laptop with VFP9 SP2 to see if it magically got fixed.
To get around the problem in VFP9, you can put the line “SET TEXTMERGE TO test ADDITIVE NOSHOW” in the CATCH block above just before the “\” command. If an error occurs, you remind TEXTMERGE that it needs to keep working. Perhaps it figures it needs some time off.
Recommendations
Unless someone has some insight or additional thoughts, I would suggest searching through your source code for cases where you are using TEXTMERGE with TRY/CATCH/FINALLY blocks. If so, insert the SET TEXTMERGE TO … line in your CATCH block. Alternately, you could use STRTOFILE() to append logging information to a file. This is the final approach I took in this program.
STRTOFILE("hello"+CHR(13),"test.txt",1) TRY USE xxx.dbf CATCH TO oErr STRTOFILE("Error: " + oErr.Message+CHR(13),"test.txt",1) ENDTRY STRTOFILE("world"+CHR(13),"test.txt",1) MODIFY FILE test.txt
I hope this helps someone, or maybe someone who knows more about this particular issue can help me!
I'm a Quant Technical Specialist (Data Warehousing and Business Intelligence), with expertise in business analysis, data modeling, and data integration. I have extensive experience developing vertical and integrated desktop, Internet, and BI applications spanning municipal, clinical, and financial industries.
