Is there a best practice for type validation when passing java objects
to a cffunction? I posted this on my blog, but figured I'd get a better
response here.

<cffunction name="doSomeThingWithJava" access="public"
returntype="void">
    <cfargument name="javaObject" type="any" required="true" hint="I am
a java object, I must be of type: com.dross.myClass"/>
    <cfset var someVar = 0/>
    <cftry>
        <cfif arguments.javaObject.getClass().getName() NEQ
"com.dross.myClass">
            <cfthrow/>
        </cfif>
        <cfcatch>
            <cfthrow
type="coldfusion.runtime.UDFMethod$InvalidArgumentTypeException" 
               message="The argument javaObject passed to function
doSomeThingWithJava() is not of type com.dross.myClass" 
               detail="Check and make sure the argument you are passing
is of the correct type"/>
        </cfcatch> 
    </cftry>
<!--- function body --->
</cffunction>

Does anyone see a better way to do this?

-Dave

----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

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

Reply via email to