Specialized error handling
Posted: Tue Oct 11, 2016 8:07 pm
I have several instances where a user defined query is entered into a character string variable. The query is then used to control selection of records during a process navigating through the database. Because the user can make a mistake, I employ a two step process.
Test query format of the query, cInputExp:
bError := ErrorBlock( {|e| Break(e)} ) // install new error handling code block
BEGIN SEQUENCE
IF ( EMPTY( cInputExp ) )
xType := "U"
ELSE
xResult := &cInputExp.
xType := VALTYPE( xResult )
ENDIF
RECOVER USING e
xType := "U"
ENDSEQUENCE
ErrorBlock(bError) // reinstall old error handler
RETURN xType
This process checks the syntax of the query but cannot validate all variable names used because the the short-cut evaluation process of the macro compiler.
Then within the data extraction loop the following is done:
bSaveErrorBlock := ErrorBlock( {|e| Break(e) } )
BEGIN SEQUENCE
DO WHILE .......
IF eval(bQuery).......
ENDIF
SKIP
ENDDO
RECOVER
ErrorBlock(bSaveErrorBlock)
END SEQUENCE
The above code does capture the error and prevent a run time error but hides what the actual error is. I am wondering how to properly use the code to provide information as to what the error actually was and the program stack/line that caused the error. I see the example in the documentation using "RECOVER use oError". Are the any other examples of how to best provide this. I know Express++ does this when trapping errors in the DC_GetRefresh() process. Are there any other good examples of how best to use the Error object so the nature of the error can be provided back to the user to assist in correcting the query.
Test query format of the query, cInputExp:
bError := ErrorBlock( {|e| Break(e)} ) // install new error handling code block
BEGIN SEQUENCE
IF ( EMPTY( cInputExp ) )
xType := "U"
ELSE
xResult := &cInputExp.
xType := VALTYPE( xResult )
ENDIF
RECOVER USING e
xType := "U"
ENDSEQUENCE
ErrorBlock(bError) // reinstall old error handler
RETURN xType
This process checks the syntax of the query but cannot validate all variable names used because the the short-cut evaluation process of the macro compiler.
Then within the data extraction loop the following is done:
bSaveErrorBlock := ErrorBlock( {|e| Break(e) } )
BEGIN SEQUENCE
DO WHILE .......
IF eval(bQuery).......
ENDIF
SKIP
ENDDO
RECOVER
ErrorBlock(bSaveErrorBlock)
END SEQUENCE
The above code does capture the error and prevent a run time error but hides what the actual error is. I am wondering how to properly use the code to provide information as to what the error actually was and the program stack/line that caused the error. I see the example in the documentation using "RECOVER use oError". Are the any other examples of how to best provide this. I know Express++ does this when trapping errors in the DC_GetRefresh() process. Are there any other good examples of how best to use the Error object so the nature of the error can be provided back to the user to assist in correcting the query.