>Hello everybody,
>
>I need a error handling procedure.Anybody if can help me please send me some code or tip .As soon as posibe!!!
>
>Thanks .
Ond of the simplest error handlers is:
* Save current on error routine
lcOnError = on('error')
* Store error flag to 0 for no error
lnErrorNo = 0
* Setup error routine
on error lnErrorNo = error()
* Do code (such as append blank) that may cause error
append blank
* Reset on error routine to original
on error &lcOnError
* Check for error
if lnErrorNo != 0
* Error occurred
wait window 'An error occurred: ' + message()
endif
Without going into a lot of detail you can also set a "global" error handler as follows:
ON ERROR DO errhandl WITH PROGRAM(), ERROR(), MESSAGE(), MESSAGE(1), LINENO(), ;
SYS(16), SYS(2018)
Create a errhandl.prg with parameters to match the above functions or additional functions. Use the errhandl.prg to log the error to an errorlog.dbf you create. Create a messagebox routine to notify the user of what to do:
PARAMETERS ;
tcProgram, ;
tnErrorNum, ;
tcErrorMsg, ;
tcSourceCode, ;
tnLineNo, ;
tcLongPrg, ;
tcErrorParam
lcTmpFil1=substr(sys(2015), 3, 10) + '.txt'
lcTmpFil2=substr(sys(2015), 3, 10) + '.txt'
LIST MEMORY TO (lcTmpFil1) NOCONSOLE
LIST STATUS TO (lcTmpFil2) NOCONSOLE
DO CASE
CASE NOT FILE("ERRORLOG.DBF")
WAIT WINDOW "Error Log Table Not Found. Error Not Logged." TIMEOUT 2
CASE NOT USED("errorlog")
SELECT 0
USE errorlog
OTHERWISE
SELECT errorlog
ENDCASE
IF UPPER(ALIAS())="ERRORLOG"
APPEND BLANK
APPEND MEMO MEMORY FROM (lcTmpFil1)
APPEND MEMO STATUS FROM (lcTmpFil2)
REPLACE DATE WITH DATE(),;
TIME WITH TIME(),;
PROGRAM WITH tcProgram,;
prog_2 WITH tcLongPrg,;
line_num WITH tnLineNo,;
error_num WITH tnErrorNum,;
source WITH tcSourceCode, ;
MESSAGE WITH tcErrorMsg,;
specific WITH tcErrorParam
ENDIF
DELETE FILE (lcTmpFil1)
DELETE FILE (lcTmpFil2)
* Notify user of error using the messagebox function
MESSAGEBOX(tcErrorMsg, , )
* Retry, return to master, or shutdown
Richard
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only