cfdocs.org /

Description

Stops the processing of a ColdFusion page at the tag location. ColdFusion returns everything that was processed before the tag. The tag is often used with conditional logic to stop processing a page when a condition occurs.

Category

Flow-control tags

Syntax

<cfabort  
    showError = "error message">
Note: You can specify this tag’s attributes in an attributeCollection whose value is a structure. Specify the structure name in the attributeCollection and use the tag’s attribute names as structure keys.

See also

cfbreak, cfexecute, cfexit, cfif, cflocation, cfloop, cfswitch, cfthrow, cftry; cfabort and cfexit in the Developing ColdFusion Applications

Attributes

Attribute

Req/Opt

Default

Description

showError

Optional

 

Error to display, in a standard ColdFusion error page, when tag executes.

Usage

When you use the cfabort and cferror tags together, the cfabort tag halts processing immediately; the cferror tag redirects output to a specified page.

If this tag does not contain a showError attribute value, processing stops when the tag is reached and ColdFusion returns the page contents up to the line that contains the cfabort tag.

When you use this tag with the showError attribute, but do not define an error page using cferror, page processing stops when the cfabort tag is reached. The message in showError displays to the client.

When you use this tag with the showError attribute and an error page using cferror, ColdFusion redirects output to the error page specified in the cferror tag.

Example

This example shows the use of cfabort to stop processing. In the second example, where cfabort is used, the result never displays.

<h3>Example A: Let the instruction complete itself</h3> 
<!--- first, set a variable ---> 
<cfset myVariable = 3> 
<!--- now, perform a loop that increments this value ---> 
<cfloop from = "1" to = "4" index = "Counter"> 
    <cfset myVariable = myVariable + 1> 
</cfloop> 
 
<cfoutput> 
<p>The value of myVariable after incrementing through the loop #Counter# times is: 
    #myVariable#</p> 
</cfoutput> 
 
<h3>Example B: Use cfabort to halt the instructions with showmessage attribute and 
    cferror</h3> 
<!--- Reset the variable and show the use of cfabort. ---> 
<cfset myVariable = 3> 
<!--- Now, perform a loop that increments this value. ---> 
<cfloop from = "1" to = "4" index = "Counter"> 
<!--- On the second time through the loop, cfabort. ---> 
    <cfif Counter is 2> 
    <!--- Take out the cferror line to see cfabort error processed by CF error page. ---> 
        <cferror type="request" template="request_err.cfm"> 
        <cfabort showerror="CFABORT has been called for no good reason"> 
<!--- Processing is stopped, ---> 
<!--- and subsequent operations are not carried out.---> 
    <cfelse> 
        <cfset myVariable = myVariable + 1> 
    </cfif>  
</cfloop> 
 
<cfoutput> 
<p> The value of myVariable after incrementing through the loop#counter# times is: #myVariable#</p> 
</cfoutput>