Microsoft Knowledge Base Email Alertz

KBAlertz.com: (178890) - FoxPro provides the ON ERROR command to allow programmers to trap specific errors that occur within applications. This article describes how to use an error trapping routine that stores relevant debugging information in a FoxPro table. The code...

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 178890 - Last Review: July 13, 2004 - Revision: 2.2

How To Use ON ERROR To Debug Applications

This article was previously published under Q178890

SUMMARY

FoxPro provides the ON ERROR command to allow programmers to trap specific errors that occur within applications. This article describes how to use an error trapping routine that stores relevant debugging information in a FoxPro table.

The code included in this article traps errors that occur within a FoxPro application and stores the following information to a table:

  • The computer name where the error occurred.
  • The error number.
  • The error message.
  • The line of code where the error occurred if the source code is available.
  • The program file where the error occurred.
  • The line number where the error occurred.
  • The name of the currently selected table when the error occurred.
  • The date and time of the error.

MORE INFORMATION

Faulty syntax and/or logic in an application can result in a wide array of trappable error conditions. Some of the errors that occur in an application may not be known until the application has been tested by end users. While the default FoxPro error message display contains useful information for a programmer, its appearance may be confusing to an end user. Likewise, end users usually have little time to carefully note and report errors that occur while an application is executing. This code may also prove useful in determining the cause of intermittent errors that occur when no one is normally present to witness the error.

  1. Create a program called Errutil.prg with the following code.
          ON ERROR DO errhand IN errutil ;
          WITH SYS(0), ERROR(), MESSAGE(), MESSAGE(1), ;
          PROGRAM(), LINENO(1), DBF(), DATE(), TIME()
          * End of error trap setup.
    
          PROCEDURE errhand
          PARAMETER m.machine, m.messgnum, m.messg, m.linecode, ;
             m.callprog, m.inline, m.OPENTABL, m.errdate, ;
             m.errtime
             m.errspace=SELECT()      && Store current work area.
             m.errorder=ORDER()       && Store current order.
          IF LEN(ALLTRIM(m.callprog))=0
             m.callprog="Command Line"
            STORE SPACE(0) TO m.linecode
          ENDIF
          outmsgline="Error ; "+m.messg+CHR(13)+"Line "+STR(m.inline)+ ;
               CHR(13)+ ;
              "program name = "+m.callprog+CHR(13)+"Syntax is  :"+m.linecode
          * Visual FoxPro users use =MESSAGEBOX(outmsgline,32+0)
          * MAC uUse the FXALERT() Function in Foxtools.mlb
          * FoxPro For Windows users use the MsgBox() Function in Foxtools.fll
          WAIT WINDOW outmsgline TIMEOUT 5 && All versions can use this syntax.
            IF !USED("ERRORLOG")
          IF FILE("ERRORLOG.DBF")
             SELECT 0
             USE errorlog
          ELSE
             SELECT 0
             thisversion=VERSION()
             IF LEFT(ALLTRIM(thisversion),6)="Visual"
                * Create Free table for Visual FoxPro Versions
                CREATE TABLE errorlog FREE (machine c(20), messgnum N(4,0), ;
                   messg c(70), linecode c(70), callprog c(40), ;
                   inline N(6,0), OPENTABL c(25), errdate d, errtime c(8))
             ELSE
                   CREATE TABLE errorlog (machine c(20), messgnum N(4,0), ;
                        messg c(70), linecode c(70), callprog c(40), ;
                     inline N(6,0), OPENTABL c(25), errdate d, errtime c(8))
                   ENDIF
                ENDIF
            ENDIF
            INSERT INTO errorlog FROM MEMVAR
            SELECT errorlog                  && Select errorlog table.
            USE                              && Close errorlog table.
            SELECT (m.errspace)              && Return to stored work area.
            IF !EMPTY(ALIAS())
          SET ORDER TO (m.errorder)
           ENDIF
          RELEASE ALL LIKE m.messgnum, m.messg, m.linecode, m.callprog, ;
              m.inline
          RETURN
    							
  2. Create a program called Ztest.prg that contains the following lines of code:
          DO errutil          && Activates ON ERROR routine in Errutil.prg.
          USE c:\noexist.dbf  && These files should not exist in order to
          DO C:\noexist.prg   && produce errors for testing purposes.
          ON ERROR            && Turns off active ON ERROR routine.
    							
  3. Type the following in the Visual FoxPro Command window:
          Do ZTest.prg.
    							
    Two Wait windows appear identifying the offending lines of code. This information is placed into the Errorlog.dbf file. The windows disappear after five seconds.
  4. Activate the Command window, then open and browse the Errorlog table.

REFERENCES

FoxPro Help, search on: "ON ERROR"; "ERROR()"; "MESSAGE()"; "SYS()"; "PROGRAM()"; "DBF()"; "LINENO()"

APPLIES TO
  • Microsoft Visual FoxPro 3.0 Standard Edition
  • Microsoft Visual FoxPro 3.0b Standard Edition
  • Microsoft Visual FoxPro 5.0 Standard Edition
  • Microsoft Visual FoxPro 5.0a
  • Microsoft Visual FoxPro 6.0 Professional Edition
  • Microsoft Visual FoxPro 3.0b for Macintosh
  • Microsoft FoxPro 2.5b
  • Microsoft FoxPro 2.5a
  • Microsoft FoxPro 2.6 Standard Edition
  • Microsoft FoxPro 2.6a Standard Edition
  • Microsoft FoxPro 2.5b for Macintosh
  • Microsoft Visual FoxPro 2.5c for Macintosh
  • Microsoft FoxPro 2.6a Professional Edition for Macintosh
  • Microsoft FoxPro 2.5b for MS-DOS
  • Microsoft FoxPro 2.6 for MS-DOS
  • Microsoft FoxPro 2.6 for SCO/UNIX
Keywords: 
kbcode kbhowto KB178890
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please