Best way to Create an Error Log for text or .DBF

jaymz69 used Ask the Experts™
What is the best approach to creating an Error Log?

when the program crashes and wants to send to Microsoft I also want to see what happened in one of the PRG's

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I am not sure that there is ONE best approach to creating an Error Log.

However it generally starts by using the ON ERROR command to direct your application to some error handling routine.

Something like:
    ON ERROR DO errhand WITH ;
                ERROR( ), MESSAGE( ), MESSAGE(1), PROGRAM( ), LINENO(1)

Then within the error handling routine (in the above example, the function errhand), you can capture a variety of various parameters into a table for subsequent review and analysis.  And then finally exit 'gracefully'.

Good Luck

CaptainCyrilFounder, Software Engineer, Data Scientist
There are 3 ways I handle errors. I start with what jrbblldr suggested then I do one of the following:

1) Write to a database using INSERT INTO error ...

2) Send an email via our online server to the support team with the details

3) Write to a log file
PROCEDURE errorhandler
LPARAMETERS nError, cMessage, cMessage1, cProgram, cProgram1, nLine, nLine1
IF TYPE('ErrorFile') = 'C'
\<<SYS(0)>> <<DATETIME()>>
\<<aAppname>> <<IIF(TYPE('cModule') <> 'C','',cModule)>> / <<VERSION(4)>>
\<<OS()>><<IIF(TYPE('cMSOVersion') <> 'C',''," / " + cMSOVersion)>>
\ERROR() = <<nError>>
\MESSAGE() = <<cMessage>>
\MESSAGE(1) = <<cMessage1>>
\PROGRAM() = <<cProgram>>
\PROGRAM(1) = <<cProgram1>>
\LINE() = <<nLine>>
\LINE(1) = <<nLine1>>

As you have noticed I also include the application name, module, OS version and Office, ...


that looks great. the programs run on a pc and you don't know there is an error until people start noticing that there report never ran.

it can be up to 24 hours before someone calls.

I like the email and log file so no matter what you should have a way to read into it and before the calls start....
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

CaptainCyrilFounder, Software Engineer, Data Scientist

I don't rely on people to call and also users are not knowledgeable enough to give you the right information.

In my email error message I also include IP address, UserID, ClientID so I know what person and what type of machine he has. This also saves a lot of time on the phone. Then they liveupdate the software.

Also your error handler should be smart enough to handle other types. There are some errors in MS Office for example which are known. I trap them and let the software continue. Also there are error using Internet Explorer. All this depends on your application.

There are some errors that require a retry after some time. You should handle that.

There are some errors that the user might have two sessions of your program open due to exclusive access. You should handle that as well.


the retry iafter some time would be a good one to on a couplr of prg


so you textmerge an then can email that?
CaptainCyrilFounder, Software Engineer, Data Scientist

The textmerge stays on the users' PC. He sends it by email later or you can prompt it to be send using his Outlook or any SMTP client.

oEmail = CREATEOBJECT(''')

I also have another procedure which I wrote that sends the error log via a website which I create.

Something like that.

That website sends the support team the email.

Having web based is a good idea as I have some clients without email to the outside world. Maybe I will set up an FTP upload too.


The information I store in an error log is

VFP Error Message
All _Screen User Properties values
All ActiveForm User Properties value if there is an activeform.
CaptainCyrilFounder, Software Engineer, Data Scientist

Yes you can do an FTP upload but it's not that secure.
Olaf DoschkeSoftware Developer
in regard to the second part: If the error is that serious, typically the C5-errors (C0000005), then there is a log using Info like ASTACKINFO() provides in a vfp9err.log but mostly you don't get more than the line of code, if it happened due to code at all.

I'll have a look into the portion, what get's sent to MS and how that would perhaps help. In fact that's rather not VFP specific but typically a dump of the C runtime having a nonresolvable error.

Typpical reasons for C5 errors in VFP apps are corrupt tables, indexes, also reports are tables. And the other one is handling object instanciation and destroy in a wrong manner, getting dangling object references.

Bye, Olaf.
Olaf DoschkeSoftware Developer

In regard to the normal error logging: I do save into a local free table, not only errors but also selfgenerated things and put that into a syslog. eg it logs when the app is started and when it's shutdown and if the last message that is found in there at a new start is not the last shutdown it therefore also detects a crash and may take additional checks before continuing with the normal startup.

I collect these local log records into a global/central log. I don't mail from customers which have maintainance and support level contracts and where I am from time to time anyway.

If it would be a standalone app or a customers site I won't visit regularly, I'd also opt for mailing this log, in an aggregated version, eg you of course often have the same error message many times from several users. It's not unusual, if our biggest customer collects hundreds of MB per month, so I even integrated a routine checking for the 2GB limit that would then create a new central log table, if that get's larger than 1.5 GB.

Bye, Olaf.
Olaf DoschkeSoftware Developer

an important thing is privacy: Only "send home" error informations, no personal data and only after the user confirms he wants to send out this. Otherwise you may end up with a spyware rating from virus/spyware scanners.

The latest thing I plan to do is sending very important errors and other informations via twitter direct messages to a corporate twitter account.

Bye, Olaf.


Thanks for all of your help

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial