home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************
- *
- * Name: MYERR.prg
- * Description: Demo replacement for Nantucket-supplied ERRORBLOCK()
- * Author: Philip H. Schwartz
- * Audience: Nantucket DEVCON '90
- * Written: June 5, 1990
- * Compiler: Clipper 5.0 V7.7 BETA
- * Options: /N
- * Linker: RTLink Version 1.3 (Clipper)
- * Library: clipper, extend
- * Inc/object: as needed
- * Headers: STD.ch, ERROR.ch
- * Copyright: (c) 1990 Philip H. Schwartz
- * Rights: All Commercial & Publishing Rights Reserved
- *
- *********************************************************************/
-
- #include "error.ch"
- #include "inkey.ch"
-
- /* Message pseudo functions */
- #define OUT(str) ErrMsg=ErrMsg+(str)
- #define OUTNL(str) ErrMsg="";ErrMsg=ErrMsg+(str)
-
- /* Definitions for MEMORY() function */
- #define MEM_TOTAL 0
- #define MEM_BLOCK 1
- #define MEM_RUN 2
-
- ***
- * MyError()
- *
- FUNCTION MyError(e)
- LOCAL i,ErrMsg,LogId,lRetry,lSubstitute
-
- /* Check for presence of Errorlog.dbf and Trace.dbf and
- build them if necessary */
- BuildFiles()
-
- /* Display instance variables in the current error object */
- IF "OBJECTS"$UPPER(GETENV("DEBUG"))
- ShowObject(e)
- ENDIF
-
- /* Check to see if RETRY is requested */
- IF ("RETRY"$UPPER(GETENV("DEBUG")) .AND. e:canRetry)
- lRetry=.f.
- @ 0,70 SAY "Retry?" GET lRetry PICTURE 'L'
- READ
- RETURN(lRetry)
- ENDIF
-
- /* Check to see if SUBSTITUTE is requested */
- IF ("SUBSTITUTE"$UPPER(GETENV("DEBUG")) .AND. e:canSubstitute)
- lSubstitute=.f.
- @ 0,65 SAY "Substitute?" GET lSubstitute PICTURE 'L'
- READ
- RETURN("*Substituted*") // example substitution
- ENDIF
-
- CLS
- /* Ignore open error and NETERR() with canDefault */
- IF (e:genCode == EG_OPEN .AND. NetErr() .AND. e:canDefault)
- RETURN (.f.) /* ignore */
- END
-
- /* Start building an error message */
- OUTNL( "Error" )
-
- /* Check for presence of subsystem */
- IF (!EMPTY(e:subsystem()))
- OUT(" "+e:subsystem()+"["+LTRIM(STR(e:subCode()))+"]")
- END
-
- /* Check for presence of description */
- IF (!EMPTY(e:description()))
- OUT(" "+e:description())
- END
-
- /* Check for presence of operation */
- IF (!EMPTY(e:operation()))
- OUT(": "+e:operation())
- END
-
- /* Check for presence of file name */
- IF (!EMPTY(e:filename()))
- OUT(": "+e:filename())
- END
-
- /* Print the message to the STD output device */
- __OUTSTD( Chr(13) + Chr(10) + ErrMsg)
-
- /* Check to see if log to error DBF is requested. The
- Log id number is constructed from the date and time. */
- IF "LOG"$UPPER(GETENV("DEBUG"))
- LogId=VAL(DTOS(DATE())+STRTRAN(TIME(),":",""))
- ErrLog(LogId,ErrMsg)
- USE trace NEW
- ENDIF
-
- /* Loop through Call Stack and print calling history to
- SCREEN and optionally generate an entry in the TRACE file. */
- i:=2
- WHILE(.t.)
- OUTNL( "Called from " + TRIM(ProcName(i)) + ;
- "(" + ALLTRIM(STR(ProcLine(i))) + ") " )
-
- __OUTSTD( Chr(13) + Chr(10) + ErrMsg)
- IF "LOG"$UPPER(GETENV("DEBUG"))
- APPEND BLANK
- REPLACE errnum WITH LogId,procname WITH PROCNAME(i),;
- procline WITH PROCLINE(i)
- ENDIF
- i++
- IF ( PROCNAME(i) == "" ) // check for end of the stack
- IF "BREAK"$UPPER(GETENV("DEBUG")) // check for BREAK request
- BREAK e // yes, pass error object on
- ELSE
- ERRORLEVEL(1) // otherwise, quit
- QUIT
- ENDIF
- END
- END
- CLOSE DATABASES
- RETURN (.f.)
-
- /* This function opens the ERRORLOG DBF and creates an entry that
- describes the nature of the current error condition. We will
- use the DUMPERRS.exe program to query this file later. */
- STATIC FUNCTION ErrLog
- PARAMETER nId,cMsg
- USE errorlog NEW
- APPEND BLANK
- REPLACE errnum WITH nId,procname WITH PROCNAME(3),;
- procline WITH PROCLINE(3),;
- version WITH IIF(VALTYPE(sys_vers)='N',sys_vers,0),;
- exelevel WITH IIF(VALTYPE(sys_exe)='N',sys_exe,0),;
- termdate WITH DATE(),termtime WITH TIME(),;
- text WITH cMsg,memtot WITH MEMORY(MEM_TOTAL),memblock WITH MEMORY(MEM_BLOCK),;
- memrun WITH MEMORY(MEM_RUN)
- USE
-
- /* If requested and if there is at least 60K, we SAVE all variables
- supported by .MEM files to ERRORLOG.mem. */
- IF "MEM"$UPPER(GETENV("DEBUG")) .AND. DISKSPACE()>60000
- SAVE ALL LIKE *.* TO errorlog
- ENDIF
- COMMIT // DOS 3.3 above, flush buffers
- TONE(500,3) // Play distinctive
- TONE(750,5) // three notes to let user
- TONE(2000,12) // know our handler has been invoked
- RETURN("")
-
- /* This function checks for the presence of the ERRORLOG.dbf and
- TRACE.dbf files and creates them if they are missing. The ERRORLOG.dbf
- contains descriptive information about the error condition and the
- TRACE.dbf contains the Call Stack data. */
- STATIC FUNCTION BuildFiles
- LOCAL aDbf
- IF !FILE("Errorlog.dbf")
- aDbf:={{"Errnum","N",14,0},;
- {"Version","N",5,2},;
- {"Exelevel","N",7,3},;
- {"Termdate","D",0,0},;
- {"Termtime","C",8,0},;
- {"Text","C",80,0},;
- {"Memtot","N",7,0},;
- {"Memblock","N",7,0},;
- {"Memrun","N",7,0},;
- {"Procname","C",10,0},;
- {"Procline","N",8,0}}
- DBCREATE("Errorlog",aDbf)
- ENDIF
- IF !FILE("Trace.dbf")
- aDbf:={{"Errnum","N",14,0},;
- {"Procname","C",10,0},;
- {"Procline","N",8,0}}
- DBCREATE("Trace",aDbf)
- ENDIF
- RETURN NIL
-
- /* This function displays the variables associated with the
- current Error Object. */
- STATIC FUNCTION ShowObject(e)
- CLS
- ? "Current Error Object Variables:"
- ? REPLICATE("-",80)
- ? "e:canDefault is: "+IIF(e:canDefault,"TRUE","FALSE" )
- ? "e:canRetry is: "+IIF(e:canRetry ,"TRUE","FALSE")
- ? "e:canSubstitute is: "+IIF(e:cansubstitute,"TRUE","FALSE" )
- ? "e:cargo() is: ",e:cargo()
- ? "e:description() is: "+e:description()
- ? "e:filename() is: "+e:filename()
- ? "e:genCode() is: "+LTRIM(STR(e:genCode()))
- ? "e:operation() is: "+e:operation()
- ? "e:osCode() is: "+LTRIM(STR(e:osCode()))
- ? "e:subCode() is: "+LTRIM(STR(e:subCode()))
- ? "e:subsystem() is: "+e:subsystem()
- ? "e:tries() is: "+LTRIM(STR(e:tries()))
- INKEY(0)
- RETURN NIL
- /*EOF*/