Strange ColdFusion Error Object
Posted At : September 15, 2008 6:15 AM | Posted By : Bob Silverberg
Related Categories: ColdFusion
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:
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:
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?
Interestingly enough, this line of code behaves as expected, but adds a "variableType" key to the error object:
<cfset StructAppend(ArrayNew(1),StructNew())>
@John: lol