Recently, I came across an interesting “catch” when passing around a cfcatch structure. I created a function that would take a cfcatch struct and send out an email with the results formatted as I wanted them to be:
<cfcomponent output="false"> <cffunction name="sendCFCatchEmail" access="public" output="false" returntype="void"> <cfargument name="cfcatchStruct" type="struct" required="yes"> <cfargument name="emailAddress" type="email" required="yes"> <cfmail from="email@email.com" subject="Error" to="#arguments.emailAddress#" type="html"> <table> <tr> <cfoutput> <td>#cfcatch.type#</td> <td>#cfcatch.message#</td> <td>#cfcatch.detail#</td> </cfoutput> </tr> </table> </cfmail> </cffunction> </cfcomponent>
What threw me was that I kept getting the following error when passing a cfcatch struct to the function:
“The CFCATCHSTRUCT argument passed to the sendCFCatchEmail function is not of type struct.”
Huh?
The difficulty I was having was that when you dump a cfcatch, it identifies itself as a struct.

It took me a little while (and maybe some googling) to figure out what was going on. Doing an “isStruct(cfcatch)” shows that for some reason, cfcatch is not a structure. What is it then? Well, an “isObject(cfcatch)” shows that it’s an object… of some kind. The particularly odd part is that “Duplicate(cfcatch)” will return a structure, not an object. Weird, huh?
<cftry> <cfset answer = 3 / "t"> <cfcatch> <cfoutput> <h2>Standard cfcatch</h2> Is Struct: #isStruct(cfcatch)#<br /> Is Object: #isObject(cfcatch)#<br /> <h2>Duplicated cfcatch</h2> Is Struct: #isStruct(Duplicate(cfcatch))#<br /> Is Object: #isObject(Duplicate(cfcatch))#<br /> </cfoutput> </cfcatch> </cftry>

In short, I just ended up changing the expected type for the cfcatchStruct argument to be “any”. I could duplicate cfcatches before sending to the function, but that’s not optimal in the least, so I just let cfcatch pretend that it’s an object if that’s what it wants to be.
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| « Aug | ||||||
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | ||
24 queries. 0.945 seconds
August 20th, 2009 at 10:03 am
when exactly did you forget how to speak english?