The following example uses SQLERROR( ) and SQLMESSAGE( ) to return an SQL error number and SQL error message to an ON ERROR routine that displays a MDI form with an error report:

ON ERROR DO ErrHndlr WITH ERROR( ), MESSAGE( ), ;
SQLERROR( ), SQLMESSAGE( ), PROGRAM( ), LINENO( )
SET DBTYPE TO DBASE
OPEN DATABASE CAClients
SET DATABASE TO CAClients
errorCode = SQLEXEC("SELECT Company, City ;
FROM Company WHERE State_Prov='CA'", "StateCA.DBF")
IF errorCode = 0
 SET DATABASE TO
 USE StateCa
 LIST
ENDIF
RETURN
 

PROCEDURE ErrHndlr
  PARAMETERS nErrorNo, cErrMess, nSQLErrorNo, cSQLErrMess, cProgram, nLineNo
  DEFINE FORM HeadsUp FROM 10,20 TO 20,55;
  PROPERTY Text "Heads Up"
  DEFINE TEXT Line1 OF HeadsUp AT 2,10 ;
  PROPERTY Text "An Error has occurred", Width 24, ColorNormal "R+/W"
  DEFINE TEXT Line2 OF HeadsUp AT 4,2;
  PROPERTY Text ;
  IIF(ERROR( )=240,cSqlErrMess,cErrMess), Width 33
  DEFINE TEXT Line3 OF HeadsUp AT 5,2;
  PROPERTY Text "Number: " + ;
  IIF(ERROR( )=240,STR(nSQLErrorNo),STR(nErrorno)), Width 24
  DEFINE TEXT Line4 OF HeadsUp AT 6,2;
  PROPERTY Text "Program: "+ cProgram, Width 22
  DEFINE TEXT Line5 OF HeadsUp AT 7,2;
  PROPERTY Text "Line #: " + STR(nLineno), Width 22
  OPEN FORM HeadsUp