Oh I see, so if I call someMethodThatDoesntExist() it will fail
siliently and if I call get/setSomePropertyThatDoesntExist() I will
get an error complaining about no var in the the VARIABLES scope.
Hows about this:
<cfcomponent>
<cfset VARIABLES.prop1 = 1>
<cffunction name="onMissingMethod">
<cfargument name="missingMethodName" type="string"
required="true">
<cfargument name="missingMethodArguments" type="struct"
required="true">
<cfset var action = Left(ARGUMENTS.missingMethodName, 3)>
<cfset var property = Right(ARGUMENTS.missingMethodName,
Len(ARGUMENTS.missingMethodName) - 3)>
<cfif action EQ "get" AND StructKeyExists(VARIABLES, property)>
<cfreturn VARIABLES[property]>
<cfelseif action EQ "set" AND StructKeyExists(VARIABLES,
property)>
<cfset VARIABLES[property] =
ARGUMENTS.missingMethodArguments[1]>
<cfelse>
<cfthrow type="InvalidMethodNameException" message="The
method
#ARGUMENTS.missingMethodName# was not found in component<br /
>#GetCurrentTemplatePath()#">
</cfif>
</cffunction>
</cfcomponent>
It throws the same exception and detail you get without the
onMissingMethod method.
Thanks all.
Adrian
On Oct 4, 7:45 pm, "Sam Larbi" <[EMAIL PROTECTED]> wrote:
> On 10/4/07, Brian Kotek <[EMAIL PROTECTED]> wrote:
>
>
>
> > I would add some kind of error handling, because right now if you pass in
> > anything other than "get" or "set", or any property that doesn't exist, it's
> > going to blow up.
>
> Similar to Brian, I was going to say you should check that the missing
> method you want to handle matches some pattern you are looking for, and if
> not, throw the error that would have occurred. There may be some cases
> where you don't want to do that, but I think in most it would be beneficial.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CFCDev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cfcdev?hl=en
-~----------~----~----~----~------~----~------~--~---