A former colleague of mine (also on this list) came up with a system in
which he called a CFC from a generic CFC wrapper.  This CFC wrapper
would call whatever CFC you specified and return a struct that contained
the result of the CFC that was called and an error.  No matter what CFC
was called, you'd always get a result and an error.  He would then check
the returned structure's error holder to see if it was 0 or if it was
something else.  If it was something else, he'd handle the display
appropriately.  Basically, when the returned structure came back, you'd
reference the result as result.employeedata.firstname instead of just
employeedata.firstname. It just buried everything one level deeper into
a common structure.  The benefit was that no matter what CFC you called,
you would always get the same type of return.  I'm not sure if this is
really good or bad, but I thought it was a neat idea for error checking
within a CFC.  I guess then you could use CFTRY/CFCATCH within the CFC
and if an error occurs, just set the error to whatever text you want to
return to the calling template.  I may not have explained it to a "T"
but I hope that helps some.

John Burns

-----Original Message-----
From: Ian Skinner [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 19, 2004 1:31 PM
To: CF-Talk
Subject: CFCs, Methods and Error catching best practice?

Ok, I've been working on this large application that is my first real
world project using CFCs.  There has been a lot of trail and error
learning over the last few months.  One issue that I haven't gotten my
head around is the best way to catch and report errors trapped inside a
CFC method, especially business logic errors, and then report this to
the user?  Any insights from old hands at CFC design and coding would be
most appreciative.

I think an example may explain what I am talking about.  I have a CFC
that has a data structure that contains one or more queries of
demographic data about a person based on their role(s).  For example a
person may be a donor and a mobile chair person.  Thus the structure
would contain two queries, a donor query and a mobile query
{basicData.donor, basicData.Mobile}.  Now to retrieve this data and use
it I have a function that returns one of these queries based on the role
requested.  This is pretty easy: <cfreturn basicData[role]>.  

It occurs to me though that I should probably error catch that the role
passed to the function actually exists and if not return an appropriate
error, but how do I do this.  The place I get lost at is the function
returning the data has been designed to expect to return a query
{<cffunction name="displayBasicData" access="public" output="false"
returntype="query...>}.  So if I place code there to capture and return
an error how would I do this with the function expecting to return a
query?  obviously I could not declare the return type and/or allow
output in the function but neither of these seem very proper to me!

Thanks for your expertise.

--------------
Ian Skinner
Web Programmer
BloodSource
www.BloodSource.org
Sacramento, CA

Confidentiality Notice:  This message including any attachments is for
the sole use of the intended
recipient(s) and may contain confidential and privileged information.
Any unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender and
delete any copies of this message.
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to