Photo from Chile

Strange ColdFusion Error Object

Today I came across a very strange ColdFusion error object. We've all seen the standard CF Error object when doing a try/catch/dump. It can be generated and viewed quite easily using a few lines of code such as this:

view plain print about
1<cftry>
2    <cfset myVar = UndefinedVar />
3    <cfcatch type="any">
4        <cfdump var="#cfcatch#" />
5    </cfcatch>
6</cftry>

That yields the following dump:

The exception being thrown is a coldfusion.runtime.UndefinedVariableException. Notice the Type key in the above struct. It's a string. We've all seen dumps like that many times. But, if I run this:

view plain print about
1<cftry>
2    <cfset str = StructNew() />
3    <cfset ArrayAppend(str,"Test") />
4    <cfcatch type="any">
5        <cfdump var="#cfcatch#" />
6    </cfcatch>
7</cftry>

I get this object:

In this case the exception being thrown is a coldfusion.runtime.NonArrayException. Look at the Type key in the Error struct. No wait, look at the type key. Wait a minute, there's a Type key (upper case "T") and a type key (lower case "t"). And neither is a string. They're both java classes. See, I told you it was strange. Strange enough to break the MXUnit Eclipse Plugin. Until Marc Esher fixed it, that is. Thanks Marc.

The docs don't specifically say that the Type key in a cfcatch struct will always be a string, so I guess this doesn't qualify as a bug, but I wonder how many other CF exceptions behave this way?

TweetBacks
Comments
great find, Bob. It was a pleasure working with you to track this down. To clarify, it was a "bug" in the mxunit RemoteFacade.cfc, not the plugin itself. The difference is subtle but the implication is whether a user would need to download a new version of mxunit or do an eclipse update for the plugin. A new version of MXUnit will be available for download tonight or tomorrow, and this new version will correctly address this bizarre issue.

Interestingly enough, this line of code behaves as expected, but adds a "variableType" key to the error object:

<cfset StructAppend(ArrayNew(1),StructNew())>
# Posted By marc esher | 9/15/08 6:27 AM
That's pretty cool. Bob is smart.
# Posted By John Allen | 9/15/08 7:03 AM
@Marc: Interesting, and thank you for responding so quickly to my bug report.

@John: lol
# Posted By Bob Silverberg | 9/15/08 1:16 PM