Title: Error Handling in ColdFusion
1Error Handling in ColdFusion
- 6 sources of application errors
- Users
- Programmers
- Hardware
- Software
- Network
- God
2Error Handling in ColdFusion
Data Validation
Error Catching
Debugging
3Error Handling in ColdFusion
- 4 ways errors are handled
- System error handling
- Site wide custom template
- CFERROR templates
- CFTRY/CFCATCH
4Error Handling in ColdFusion
- System error handling
- Stops the execution of the page
- Writes the error to the log
- No user control
- Error information controlled by CF Admin (Debug)
5Error Handling in ColdFusion
- Site Wide Error Handling
- Stops page execution
- Does not write to log
- Takes place of standard error display page
- Allows ALL ColdFusion tags to be shown
- Effective from ColdFusion 4.01 on
- Set in CF Admin
6Error Handling in ColdFusion
- CFERROR Tag
- 4 modes of execution
- Runs a template when an error occurs
- Introduced in ColdFusion 2?
- Is still actually useful
7Error Handling in ColdFusion
- CFERROR TypeValidate
- Used for server side data validation
- Will be (was) covered in Data Validation section
8Error Handling in ColdFusion
- CFERROR TypeRequest
- Lowest level error handler
- Operates after any and all other handlers
- Stops page execution
- Writes error information to log
- Does not allow ANY ColdFusion tags in template.
Has limited error display information - Will be re-thrown on additional errors
- Should be used as a last resort in an
application
ltCFERROR TYPE"REQUEST" TEMPLATE"\cfide\REQUEST.c
fm"gt
9Error Handling in ColdFusion
- CFERROR TypeException
- Overrides site wide error handling
- Stops page execution
- Allows ALL ColdFusion tags to be used in template
- Does not write to log
ltCFERROR TYPE"EXCEPTION" TEMPLATE"\cfide\EXCEPTI
ON.cfm"gt
10Error Handling in ColdFusion
- CFERROR TypeMonitor
- Top level error handler
- Does not stop page execution
- Allows ALL ColdFusion tags in template
- Does not write to log
- Will only be used once, which may result in it
existing within another error handler (especially
site wide handlers) - Should be used on pages with CFTRY/CFCATCH
ltCFERROR TYPE"MONITOR" TEMPLATE"\cfide\MONITOR.c
fm"gt
11Error Handling in ColdFusion
ltDLgt lt!--- Loop over Error structure. This is
created automatically when an error is thrown
---gt ltCFLOOP COLLECTION"Error" ITEM"Key"gt
ltCFOUTPUTgt ltCFIF IsSimpleValue(ErrorKey)gt
lt!--- Display error text ---gt
ltDTgtltBgtKeylt/Bgt - ltDDgtErrorKey
ltCFELSEIF IsArray(ErrorKey)gt lt!---
Display dump of all tags that were executed until
the error occured. Note that this only covers the
executed tags, not all that exist. ---gt
ltDTgtltBgtKeylt/BgtltOLgt ltCFLOOP INDEX"i"
FROM"1" TO"ArrayLen(ErrorKey)"gt
ltLIgt ltCFLOOP COLLECTION"ErrorKe
y i" ITEM"Key2"gt ltBgtkey2lt/Bgt -
ErrorKey iKey2ltBRgt
lt/CFLOOPgt lt/CFLOOPgt lt/OLgt
lt/CFIFgt lt/CFOUTPUTgt lt/CFLOOPgt lt/DLgt
12Error Handling in ColdFusion
BROWSER - Mozilla/4.0 (compatible MSIE 5.5
Windows NT 4.0) DATETIME - 07/18/00 132109
DETAIL - DIAGNOSTICS - An error occurred while
evaluating the expression name is t Error near
line 10, column 11. Error resolving parameter T
ColdFusion was unable to determine the value of
the parameter. This problem is very likely due to
the fact that either You have misspelled the
parameter name, or You have not specified a
QUERY attribute for a CFOUTPUT, CFMAIL, or
CFTABLE tag. The error occurred while processing
an element with a general identifier of (CFIF),
occupying document position (101) to (1016) in
the template file E\HTDocs\cferror.cfm.
13Error Handling in ColdFusion
ERRNUMBER - 16396 ERRORCODE - EXTENDEDINFO -
GENERATEDCONTENT - HANDLER_TYPE - ERROR
HTTPREFERER - MAILTO - mdinowit_at_coreactive.com
MESSAGE - An error occurred while evaluating
the expression name is t Error near line 10,
column 11. Error resolving parameter T
ColdFusion was unable to determine the value of
the parameter. This problem is very likely due to
the fact that either You have misspelled the
parameter name, or You have not specified a
QUERY attribute for a CFOUTPUT, CFMAIL, or
CFTABLE tag.
14Error Handling in ColdFusion
QUERYSTRING - REMOTEADDRESS - 199.105.219.211
TAGCONTEXT 1 COLUMN - 1 ID - CFTRY LINE -
7 TEMPLATE - E\HTDOCS\CFERROR.CFM 2 COLUMN -
8 ID - CFSER LINE - 7 TEMPLATE -
E\HTDOCS\CFERROR.CFM TEMPLATE -
E\HTDocs\cferror.cfm TYPE - EXPRESSION
15Error Handling in ColdFusion
- CFTRY
- Defines a block of code to be tried.
- If an error occurs within the block of code, a
CFCATCH can be attempted - Must have at least one CFCATCH tag pair
associated with it. This CFCATCH must be the last
CF tag before the closing CFTRY
ltCFTRYgt ... Add code here ltCFCATCH
TYPE"exceptiontype"gt ... Add exception
processing code here lt/CFCATCHgt ... Additional
CFCATCH blocks go here lt/CFTRYgt
16Error Handling in ColdFusion
- CFCATCH
- Used inside a CFTRY block
- Catches an error
- Allows an error to be fixed or avoided without
aborting the page run - Can be targeted to specific error types
APPLICATION (default) Database Template
Security Object MissingInclude Expression
Lock Custom_type Any (default)
17Error Handling in ColdFusion
ltCFTRYgt ltCFQUERY NAME"TestQuery"
DATASOURCE"cfsnippets1"gt SELECT FROM
Table lt/CFQUERYgt ltPgt... other processing goes
here ltCFCATCH TYPE"Database"gt ltCFQUERY
NAME"TestQuery" DATASOURCE"cfsnippets2"gt SELEC
T FROM Table lt/CFQUERYgt lt/CFCATCHgt lt/CFTRYgt
18Error Handling in ColdFusion
ltCFTRYgt This will be shown and the include will
fail ltCFINCLUDE TEMPLATE"nothing.cfm"gt This
will not be shown ltCFCATCH TYPE"MissingInclude"gt
This will be shown lt/CFCATCHgt This will not be
shown lt/CFTRYgt This will be shown
19Error Handling in ColdFusion
Order of error handler operation Monitor (does
not abort. Used when valid CFCATCH is detected.
Allows CF tag processing. Will RE-THROW in no
valid CFCATCH) CFTRY/CFCATCH (does not abort.
Assumes a valid CFCATCH) Exception (aborts
run. Overrides site wide handling. Disabled when
CFTRY exists?) Site wide (aborts run) Request
(aborts run. will ALWAYS be overridden by site
wide handling. Does not allow CF tag processing,
only special error scope variables.)
20Error Handling in ColdFusion
- Speed and Overhead
- Very little overhead
- Error handlers are not processed unless used
- Should be used with ALL applications
21Error Handling in ColdFusion
- CFTHROW
- Allows for custom errors to be caught with
CFTRY/CFCATCH - Error message and details can be specified
- Can be handled as an Application or Any error
type as well as a custom one