ON ERROR DO errHandler WITH ; ERROR( ), MESSAGE( ), MESSAGE(1), PROGRAM( ), LINENO( ) USE nodatabase ON ERROR && Restores system error handler. PROCEDURE errHandler PARAMETER merror, mess, mess1, mprog, mlineno CLEAR ? 'Error number: ' + LTRIM(STR(merror)) ? 'Error message: ' + mess ? 'Line of code with error: ' + mess1 ? 'Line number of error: ' + LTRIM(STR(mlineno)) ? 'Program with error: ' + mprog ENDPROC | |
LOCAL x AS Integer, y AS Integer, result AS Integer
LOCAL oErr AS Exception, oErr1 AS Exception
TRY
x = 1
TRY
USE nothing
GO TOP
y = nothing.col1
CATCH TO oErr
oErr.UserValue = "Nested CATCH message: Unable to handle"
?[: Nested Catch! (Unhandled: Throw oErr Object Up) ]
?[ Inner Exception Object: ]
?[ Error: ] + STR(oErr.ErrorNo)
?[ LineNo: ] + STR(oErr.LineNo)
?[ Message: ] + oErr.Message
?[ Procedure: ] + oErr.Procedure
?[ Details: ] + oErr.Details
?[ StackLevel: ] + STR(oErr.StackLevel)
?[ LineContents: ] + oErr.LineContents
?[ UserValue: ] + oErr.UserValue
THROW oErr
FINALLY
?[: Nested FINALLY executed ]
IF USED("nothing")
USE IN nothing
ENDIF
ENDTRY
result = x-y
CATCH TO oErr1
?[: Outer CATCH! ]
?[ Outer Exception Object: ]
?[ Error: ] + STR(oErr1.ErrorNo)
?[ LineNo: ] + STR(oErr1.LineNo)
?[ Message: ] + oErr1.Message
?[ Procedure: ] + oErr1.Procedure
?[ Details: ] + oErr1.Details
?[ StackLevel: ] + STR(oErr1.StackLevel)
?[ LineContents: ] + oErr1.LineContents
?[ ->UserValue becomes inner exception THROWn from nested TRY/CATCH ]
?[ Error: ] + STR(oErr1.UserValue.ErrorNo)
?[ Message: ] + oErr1.UserValue.Message
?[ Procedure: ] + oErr1.UserValue.Procedure
?[ Details: ] + oErr1.UserValue.Details
?[ StackLevel: ] + STR(oErr1.UserValue.StackLevel)
?[ LineContents: ] + oErr1.UserValue.LineContents
?[ UserValue: ] + oErr1.UserValue.UserValue
result = 0
FINALLY
?[: FINALLY statement executed ]
ENDTRY
RETURN result