Wiki Home

Error Handling 101


Namespace: VB
Welcome to Error Handling 101.
* Program ErrHlr
* A simple Error Handler
* It displays the error, and gives the user some options

lParameters ;
	tnLin, ;
	tcSrcCod
* tnLin - Line error occured on
* tcSrcCod - source code of line

#DEFINE CRLF chr(13) + chr(10)

local ;
	laErr[1], ;
	lcMsg, ;
	lcPrgStk, ;
	lnI

aError( laErr )
	
lcMsg = "An error has occured." + CRLF
	
lcMsg = lcMsg + ;
	"Error #" + transform( laErr[1] ) + ', "' + laErr[2] + '"' + CRLF

lcMsg = lcMsg + ;
	"Line #" + transform( tnLin ) + ', "' + tcSrcCod + '"' + CRLF
	
* If a trigger failed, display which one
if laErr[1] = 1539
	lcMsg = lcMsg + ;
		"laErr[5]=" + transform( laErr[5] ) + substr( "InsertUpdateDelete", laErr(5)*6-5, 6 )
endif		
		
* show what programs were called to get to the error
lcPrgStk = program()
for lnI = program(-1)-1 to 1 step -1
  lcPrgStk = lcPrgStk + ", " + program ( lnI )
endfor
lcMsg = lcMsg +  ;
	'Call Stack:' + lower( lcPrgStk ) + CRLF

* 2 - Abort, Retry, Cancel buttons
* 3 - Yes, No, and Cancel buttons 		

lnAns = MESSAGEBOX( lcMsg, 2 + 48  )

DO CASE
	CASE lnAns = 3				&& Abort
		cancel
	CASE lnAns = 4				&& Retry
		set step on
		retry
	CASE lnAns = 5				&& ignore
		return
ENDCASE

return

Contributors Carl Karsten
Category Error Handling
( Topic last updated: 2005.04.06 08:28:32 AM )