在这个标签的位置中止这个正在执行的Coldfuion页面. Coldfuion会传回在这个标签之前执行的结果.这个标签主要用于中止执行一个网页内的条件判断逻辑内.
<cfabort
showError = "error message">
cfbreak, cfexecute, cfexit, cfif, cflocation, cfloop, cfswitch, cfthrow, cftry; "cfabort and cfexit" 在 ColdFusion 开发者指南
| 属性 |
必须/可选 |
默认 |
描述 |
|---|---|---|---|
showError |
可选 |
|
自定错误信息显示, 当这个标签配合这个属性执行时,要显示的错误信息,这些错误信息是定义在标准的ColdFusion error页面内. |
当cfabort和cferror一起使用时,cfabort会立即中止这个处理; cferror会将执行的结果重新导向到另一个指定页面上.
如果这个标签不包含showError属性值,会立即停止网页继续向下执行,并传回<cfabort>这个标签之前的执行结果.
当你使用标签的showError属性,但未使用cferror定义一个错误页面时,页面一执行到cfabort,页面的访问立即停止.这个错误信息透过showError在客户端显示出来.
当你将showError和cferror同时使用的时候,ColdFusion会将错误信息重新导向到cferror所指定的错误讯息中.
以下范例展示使用cfabort中止页面执行操作.在第二个范例中,cfabort被使用的位置,错误信息不会再被显示出来.
<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>