<CFABORT> Tag - ColdFusion


>> Return to CF Tag List

The <CFABORT> tag allows you to stop the execution of a ColdFusion page dead in its tracks. This can be handy for stopping the processing of a page when some sort of error condition occures.

One of the recent uses I have found for this tag is to use it in conjunction with the CFINCLUDE tag to conditionally bring up a page based on specific conditions... such as what the browser is. For example: on a regular page, near the top of the page, have code that checks if the browser is Safari for the iPhone. If this is true, do a CFINCLUDE to bring up the iPhone version of the page. Then do a CFABORT tag so that the rest of the regular page is not processed.

Syntax:
   <CFABORT [SHOWERROR="Error Text"]>

Attributes:
ATTRIBUTE DESCRIPTION COMMENTS
SHOWERROR Error Message Text Optional.


Example:
<CFIF NOT IsDefined("URL.person")>
   <CFOUTPUT>Person Parameter missing. Cannot view Page!</CFOUTPUT>
   <CFABORT> <-- stop processing this page! -->
</CFIF>

See Also: <CFEXIT> <CFBREAK>


  <CFABORT> Comments from Adobe LiveDocsLiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-pt1.htm
/me sniggers quietly...

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-pt1.htm
fifthtime:

I believe that would be the expected behavior, unless you have a cferror template defined.

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-pt1.htm
this tag is not working in 6.1 and I am getting no help.

<CFIF IsNumeric(memid) IS "No">
<CFABORT SHOWERROR = "Illegal Member Number.">
</CFIF>

gives me error
Error occurred while processing request.
Illegal Member Number.


The error occurred in D:\HTML\Users\userweb3\Html\listresults1.cfm: line 55
Called from D:\HTML\Users\userweb3\Html\listresults1.cfm: line 53
Called from D:\HTML\Users\userweb3\Html\listresults1.cfm: line 47
Called from D:\HTML\Users\userweb3\Html\listresults1.cfm: line 1

53 : <CFELSE>
54 : <CFIF IsNumeric(memid) IS "No">
55 : <CFABORT SHOWERROR = "Illegal Member Number.">
56 : </CFIF>

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-pt1.htm
We are working to improve the examples in the ColdFusion reference pages. We propose to replace/add the current example on this page with the the following examples. If you have any comments on this example, add them to this page.

<!--- TO RUN EXAMPLE C:

- Comment out Example B code

- Uncomment Example C code

- Create error template from cferror tag examples in online CFML Tag Reference --->

<!---

<h3>Example C: 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#

</cfoutput>

--->



[Top]


Recommended Books

[Top]

Web Sites

[Top]

Copyright © 2003- 2008, Orville Paul Chomer, All Rights Reserved