cfdocs.org /

Description

Used inside a cftry tag. Code in the cffinally block is processed after the main cftry code and, if an exception occurs, the cfcatch code. The cffinally block code always executes, whether or not there is an exception.

Category

Exception handling tags

Syntax

<cftry> 
    try code    <cfcatch> 
        catch code    <cfcatch> 
    ... 
    <cffinally> 
        final code    </cffinally> 
</cftry>

See also

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

History

ColdFusion 9: Added the tag

Usage

The cffinally tag is optional in a cftry block, and the block can have only one cffinally tag. Put the cffinally tag at the end of all cftry block, after any cfcatch blocks. This tag requires an end tag. You can nest cftry/cfcatch/cffinally blocks.

Use the cffinally tag for code that should execute whether or not an exception occurs. For example, use it to free up resources.

Example

<h3>cffinally Example</h3> 
<!--- Open a cftry block. ---> 
<cftry> 
    .... 
    <cfcatch type = "Database"> 
    .... 
    </cfcatch> 
    <cffinally> 
    .... 
    <!--- Do some cleanup here before leaving cftry block ---> 
    .... 
    </cffinally 
</cftry>