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]