Sean,

Thanks for your help. I guess I am still looking at this in a standard cfml
way and getting a little confused in the OOP side of this.

I guess your saying

<cftry>
 <cfset user = users.getUser('testuser') />
 <cfcatch type="any">
 </cfcatch>
</cftry>


Where I would be thinking in the lines of

<cfset user = users.getUser('testuser') />
<cfif user>
</cfif>


Regards,
Andrew Scott
 
Quote of the Day:
A good intention but fixed and resolute - bent on high and holy ends, we
shall find means to them on every side and at every moment; and even
obstacles and opposition will but make us "like the fabled spectre-ships,"
which sail the fastest in the very teeth of the wind. - Ralph Waldo Emerson
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Sean Corfield
Sent: Sunday, 23 October 2005 3:22 PM
To: [email protected]
Subject: Re: [CFCDev] CFC return types

On 10/22/05, Andrew Scott <[EMAIL PROTECTED]> wrote:
> If you don't mind I would like an example to clarify, in this example I am
> checking to see if a user exists, it returns the user object if it does.
So
> when it returns back to the caller how do I handle it, if you can give me
an
> example to help clarify what your saying that would be much appreciated.

<cfif userExists>
    <cfreturn theUser/>
<cfelse>
    <cfthrow type="user.nonexistent" message="User #username# does not
exist"/>
</cfif>

And then in your calling code you can safely say the following:

<cfset user = obj.getUser(username)/>

and go on to use the 'user' variable knowing it will be set correctly.

Surround the code with <cftry> / <cfcatch> to handle the non-existent
user case (or let it percolate up to the next level).

This is much more robust that trying to handle null return values inline.
--
Sean A Corfield -- http://corfield.org/
Got frameworks?

"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 words 'unsubscribe cfcdev' as the subject of the
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting
(www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]







----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]


Reply via email to