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.


    Code that might throw an exception 
    One or more cfcatch blocks 

See also

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


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


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.


<!--- cftry example, using TagContext to display the tag stack. ---> 
<h3>cftry Example</h3> 
<!--- Open a cftry block. ---> 
    <!--- Note misspelled tablename "employees" as "employeeas". ---> 
    <cfquery name = "TestQuery" dataSource = "cfdocexamples"> 
        SELECT * 
    <!--- <p>... other processing goes here ---> 
    <!--- specify the type of error for which we search ---> 
    <cfcatch type = "Database"> 
    <!--- the message to display ---> 
        <h3>You've Thrown a Database <b>Error</b></h3> 
            <!--- and the diagnostic message from the ColdFusion server ---> 
            <p>Caught an exception, type = #CFCATCH.TYPE# </p> 
            <p>The contents of the tag stack are:</p> 
            <cfloop index = i from = 1  
                    to = #ArrayLen(CFCATCH.TAGCONTEXT)#> 
                <cfset sCurrent = #CFCATCH.TAGCONTEXT[i]#> 
                <br>#i# #sCurrent["ID"]#