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.


Tag example

  <cfquery name="getCountofReminders" datasource="dsn">
    select count(id) from reminders where id = <cfqueryparam value="#arguments.id#" cfsqltype="cf_sql_number">
  <cfcatch type="database">
      <p>There was a problem getting a count of your reminders)</p>
    <cfdump var=#cfcatch#>

Script example

try {
	a = 2/0
catch(any e){
	writeOutput("Caught an error.");

See also