Error Trapping

Example 1


dim cn as sql::Connection

cn.open("::name::conn")

vsql = "SELECT * FROM mytable"

if cn.execute(vsql) = .f.

  save_to_file("MY_REFERENCE_NOTATION|" + cn.callresult.text,"c:\mylog.txt")

  goto end_of_script

end if

cn.close()

END        

end_of_script:


Example 2 - using custom error report function AEX


dim cn as sql::Connection

cn.open("::name::conn")

vsql = "SELECT * FROM abc"

if cn.execute(vsql) = .f.

errorout("MY_REFERENCE_NOTATION|" + cn.callresult.text)

  goto end_of_script

end if

cn.close()

END        

end_of_script:


Custom Error Function


FUNCTION errorout AS C (errormsg AS C = "", severity AS N = 0 )

       

       fldr = "\a5\logs"

       logfile = fldr + "\sql_error.log"

       if file.exists(fldr) = .f.

               file.dir_create_recurse(fldr)

       end if 

       vErrorMsg = time("yyyy/MM/dd 0h:0m:0s") + "|" + ErrorMsg + crlf() + replicate("-",10) + crlf()

       file.append_line(logfile,vErrorMsg)        

       if severity > 4

'                email_send("YOUR EMAIL ADDRESS", "A5 Website Error",vErrorMsg)

'                put what you want to do if the error is critical

       end if 


END FUNCTION