ColdFusion Error Handling

Download Report

Transcript ColdFusion Error Handling

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