<cftry>
Used with one or more <cfcatch> tags, the cftry tag lets you catch and process exceptions in CFML pages.
Exceptions include events that disrupt the normal flow of instructions in a CFML page, such as failed database operations, missing include files, and developer-specified events.
This tag must have a body.
This tag is also supported within <cfscript>
<cftry><!--- body ---></cftry>
This tag does not use any attributes.
Examples
Tag example
<cftry>
<cfquery name="getCountofReminders" datasource="dsn">
select count(id) from reminders where id = <cfqueryparam value="#arguments.id#" cfsqltype="cf_sql_number">
</cfquery>
<cfcatch type="database">
<cfoutput>
<p>There was a problem getting a count of your reminders)</p>
</cfoutput>
<cfdump var=#cfcatch#>
</cfcatch>
</cftry>
Script example
try {
a = 2/0
writeDump("#a#");
}
catch(any e){
writeOutput("Caught an error.");
}
See also
- Core CFML Language
- Exception Output
- Retry
- <cfcatch>
- <cffinally>
- <cfrethrow>
- <cfretry>
- <cfthrow>
- Search Issue Tracker
- Search Lucee Test Cases (good for further, detailed examples)