Stops processing of a page at the tag location. ColdFusion returns everything that was processed before the cfabort
tag. The cfabort
tag is often used with conditional logic to stop processing a page when a condition occurs.
<cfabort showError = "error_message">
cfbreak,
cfexecute,
cfexit,
cfif cfelseif cfelse,
cflocation,
cfloop,
cfswitch cfcase cfdefaultcase,
cfthrow,
cftry cfcatch
Parameter |
Description |
---|---|
showError |
Optional. The error to display when cfabort executes. The error message displays in the standard ColdFusion error page. |
Remember that when combining cfabort
and cferror
, cferror
is meant to redirect output to a specified page. The cfabort
tag halts processing immediately.
If the cfabort
tag does not contain a showError
attribute value, processing stops immediately and ColdFusion returns the page contents up to the line that contains the cfabort
tag.
When using cfabort
with the showError
attribute alone (without defining an error page using cferror
), page processing stops when the cfabort
tag is reached. The message defined in showError
is displayed to the client.
In a page in which you've defined both an error page using cferror
and a cfabort
tag using the showError
attribute, ColdFusion redirects output to the error page specified in the cferror
tag.
<!--- this example demonstrates the use of cfabort
to stop the processing of a cfloop. Note that in the
second example, where cfabort is used, the result never
displays --->
<html> <head> <title>cfabort Example</title> </head> <body bgcolor = FFFFFF> <H1>cfabort Example</H1> <P> <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# </cfoutput> <!--- reset the variable and show the use of cfabort ---> <H3>Example B: Use cfabort to halt the instruction</H3> <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> <cfabort> <!--- the processing is stopped, and subsequent operations are not carried out by the CFAS ---> <cfelse> <cfset myVariable = myVariable + 1> </cfif> </cfloop> <cfoutput> <P> The value of myVariable after incrementing through the loop #counter# times is: #myVariable# </cfoutput> </body> </html>