118
Chapter 6: Using Flash Remoting with ColdFusion MX
To simplify the debugging of your ColdFusion code, use the
cftry
and
cfcatch
tags in your
ColdFusion page or component to catch errors and return helpful error messages about the errors
to the Flash application. For example, the ColdFusion page causeError.cfm contains the following
code:
<cftry>
<cfset dev = Val(0)>
<cfset Flash.Result = (1 / dev)>
<cfcatch type="any">
<cfthrow message="An error occurred in this service: #cfcatch.message#">
</cfcatch>
</cftry>
In this example, the second
cfset
tag fails because it causes a divide-by-zero error. The
message
attribute of the
cfthrow
tag describes the error; ColdFusion returns this attribute to the Flash
application. For more information on using the
cftry
and
cfcatch
tags, see
Developing
ColdFusion MX Applications with CFML.
To handle the error in your Flash application, you create a fault handler for the
causeError()
method, as follows:
import mx.rpc.FaultEvent;
//…
function causeError_Fault ( fault:FaultEvent ):Void
{
resultBox.text = fault.fault.faultstring;
}
In this example,
resultBox
is a Flash text box that displays the error message created by the
cfthrow
tag.
For more information on handling errors, see
Chapter 2, “Using Flash Remoting ActionScript,”
on page 29
.