This situation is the perfect place to use a CFTHROW tag.  If the role name
is invalid, just throw an exception (InvalidRoleException, or something)
from your CFC.  You can leave your method with returntype="query" as it
should be, and use the exception to communicate with the calling code.

In your calling code, you watch for the exception with a CFTRY..CFCATCH, and
if it's thrown, do "something".  Otherwise you just proceed as normal,
exactly as you do right now.

The "something" that you do depends on the severity of the exception.  It's
perfectly legit for the "something" to just be another CFTHROW tag or a
CFRETHROW tag to push the error up higher in the chain of command.  If it's
truly a fatal error, it'll get caught by you error handling template (which
should ALWAYS be defined, even if it's never used).  Otherwise it'll get
caught at some point and handled, either by the code trying another route
towards successful execution (such as selecting a default role), or stopping
execution and requesting different inputs from the user (reload the "Select
a role" form).  If the resolution involves displaying something to the user,
the exception needs to propogate all the way back up to the presentation
layer, which could easily be through a significant number of backend CFCs.

Cheers,
barneyb

> -----Original Message-----
> From: Ian Skinner [mailto:[EMAIL PROTECTED]
> Sent: Thursday, February 19, 2004 10:31 AM
> 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