Error Handling Michael Smith President TeraTech, Inc ColdFusion, Database & VB custom development
Introduction n Why handle errors? n Default CF handler u Display u Error log n Professional n Security n Logging/
Overview Here is what we will be covering: Types of errors Administrator settings CFERROR CFCATCH/CFTRY/CFTHROW Error logging Error Tips
Types of Errors n Syntax u CF u SQL (runtime) n Database u Connection u permissions n Includes n Objects n Expressions n Locking n Other, 404, 403 etc
Server config
CFERROR n n Only affects display of message n No CF code in handling page - just “error.” Variables: u Diagnostics, MailTo, DateTime, Browser, RemoteAddress, HTTPReferer, Template, QueryString n Use javascript to resubmit to CFML OnLoad
Structured Error Handling n Some terms n Exception = error n Throw = control move to error handler. Error is Raised n Try = block to try and find errors n Catch = receive the error and process
CFTRY/CFCATCH you code here… handle handle
CFCATCH variables n CFCATCH. u Detail u Message u NativeErrorCode * u SQLState * u Type * = (database only)
Logging errors What do you do when you catch an error? n CFMAIL yourself n Append to table or text file n Send to error report or feedback page n CFABORT or Resume processing
CFTHROW n Create your own errors n Jump out of loops etc - a GOTO for CF. n Test error handling
Error issues n Don’t use CFTRY in application.cfm as will never end (Though what about OnRequestEnd.cfm?) n Cover whole page in CFTRY n No code between and n Catch expected errors separately - eg object down - and offer retry
CF log files n C:\CFUSION\LOG\ n C:\CFUSION\MAIL\LOG\ n Free log viewer from (see next page for screen shot)
Logviewer
See also n Studio Debugger n Admin debug options n Server monitors n 404 error handler
Resources n CFDOCS n Ben Forta Advanced Book Ch 19 n cf-talk list n