Whatever message this page gives is out now! Go check it out!

cftry

Last update:
May 18, 2026

Description

Used with one or more  cfcatch  tags. Together, they catch and process exceptions in ColdFusion pages. Exceptions are events that disrupt the normal flow of instructions in a ColdFusion page, such as failed database operations, missing include files, and developer-specified events.

Category

Syntax

Code that might throw an exception
One or more cfcatch blocks
</cftry>

See also

cfcatch cffinally cferror cfrethrow cfthrow onError Handling Errors  in the Developing ColdFusion Applications

History

ColdFusion MX: Changed  cfscript  to include try and catch statements that are equivalent to the cftry and cfcatch tags.

Usage

Within a cftry block, put the code that might throw an exception, followed by one ore more cfcatch tags that catch and process exceptions. This tag requires an end tag.

Example

 
<cfscript>
    myQuery = queryNew("id,name,amount","Integer,Varchar,Integer", 
                [ 
                        {id=1,name="One",amount=15}, 
                        {id=2,name="Two",amount=18}, 
                        {id=3,name="Three",amount=32} 
                ]); 
</cfscript>
<cftry>
    <cfloop query = "myQuery">
        <!--- Use a non-existent column --->
        <cfoutput>#location#</cfoutput> 
    </cfloop>
    <cfcatch type="any">
            <p><strong>Incorrect column referred. Please use the correct column.<strong><p>
    </cfcatch>
</cftry>
Output
Incorrect column referred. Please use the correct column.

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page