Howdy,
Concerning Error handling, Sean C. sent this reply to my question (his email
follows below these code samples of mine), and I have run with it. I do
wrap the the methods of the cfcs, and the facade cfcs to catch errors, but
on error I call a private method in the cfc "throw()" which handles the
exception by calling various other cfcs to log it, notify someone, retry,
whatever? There is probably a better way to do it, but this is how I am
currently handling it.
Excerpt from a cfc called by the facade cfc:
<CFCATCH type="database">
<CFSCRIPT>
//error msg used by flash client
errorStruct.errorMessage = "An Unexpected Error Has Occured. The
Administrator Has Been Notified. Please Retry Your Last Action.";
errorStruct.errorType = cfcatch.type;
errorStruct.errorCode = cfcatch.NativeErrorCode;
errorStruct.errorDetail = cfcatch.detail;
errorStruct.errorExtendedInfo = cfcatch.SQLState;
errorStruct.errorStatus = 1;
</CFSCRIPT>
<CFSET throw(errorStruct)>
</CFCATCH>
Throw() of the cfc
<CFFUNCTION access="private" displayname="Error Handler" returntype="void"
name="throw" output="false">
<CFARGUMENT name="errorStruct"
required="true" default="" type="struct">
<cfset
setErrorStruct(arguments.errorStruct)>
<CFTHROW
message="#arguments.errorStruct.errorMessage#"
type="#arguments.errorStruct.errorType#"
detail="#arguments.errorStruct.errorDetail#"
errorcode="#arguments.errorStruct.errorCode#"
EXTENDEDINFO="#arguments.errorStruct.errorExtendedInfo#">
</CFFUNCTION>
The cfc called by the facade executes the cfthrow, that is then caught by
the facade cfcs error handling, here:
catch (any excpt)
{
resultStruct.success = 0;
resultStruct.error =
listingResults.getErrorStruct();
throw(resultStruct.error);
}
Here the result struct used by the flash client is set up (the flash client
is set up to ref. the resultStruct.error if the success = 0) the throw() is
executed and the error is logged, or whatever.
<CFFUNCTION access="private" returntype="void" output="false" name="throw">
<CFARGUMENT name="errorInfo" required="true"
type="struct">
Do Stuff!!
</CFFUNCTION>
BELOW IS THE EMAIL SEAN SENT THAT I BUILT THIS IDEA FROM!!!!
-----Original Message-----
From: Sean A Corfield [mailto:[EMAIL PROTECTED]
Sent: Wednesday, May 14, 2003 11:00 PM
To: [EMAIL PROTECTED]
Subject: Re: [CFCDev] Error Handling Best Practices
On Wednesday, May 14, 2003, at 08:22 US/Pacific, Justin Balog wrote:
> Do you mean output directly in the CFC, or output as a indicator that
> is
> returned to the controller? I am asking this because if I am trying to
> preserve encapsulation within my cfc, I feel I need to let the view and
> facade.cfc know that an error has occurred, so that they can do
> something
> with it. Does that make sense?
Note that if you're using Flash Remoting, you'll find throwing
exceptions to Flash doesn't work too well (the exception is buried in
other NetServices stuff).
Here's how I suggest you do things:
CFCs - not web accessible
throw exceptions for 'unexpected' errors (see below)
CFCs - facade that invokes other CFCs
catch exceptions, map to struct with boolean and data:
result.success (boolean)
result.data (if result.success)
result.error (if not result.success)
Flash view
always get onResult(resultStruct) called
can check resultStruct.success and either process
result.data or display / deal with result.error
What is an 'unexpected' error?
If you're reading a file, you expect to hit EOF.
If you're iterating over a list, you expect to hit end of list.
An 'unexpected' error is one that you do not expect to get if things
are running properly.
Is bad user input an 'unexpected' error?
Depends, but in general 'no'. You're validating user input so you
might reasonably 'expect' it to be invalid. This is somewhat of a grey
area...
Sean A Corfield -- http://www.corfield.org/blog/
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev'
in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev'
in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).