A week or so ago a reader asked me about an odd change he saw when dumping exceptions in ColdFusion. In a "normal" error, he saw the following keys in the Exception object: Detail, ErrNumber, Message, StackTrack, TagContext, Type. These were all expected (although there can be more based on your error). Then he noticed that if an error occurred within Application.cfc, something else was added. To test this, I added the following:
<cfreturn true>
</cffunction>
<cffunction name="onRequestStart" returnType="boolean" output="false">
<cfargument name="thePage" type="string" required="true">
<cfif structKeyExists(url, "x") >
<cfthrow message="I made a boo boo." detail="method level detail">
</cfif>
To test, I simply requested a file and added x=1 to my URL. When this error occurs, both a RootCause and a Cause key exist in the object.
While RootCause is documented, Cause was not. I bugged some folks at Adobe about this and Chandan Kumar of Adobe told me the following:
-
First, Cause is a copy of RootCause. You don't have to look at them both for information about the error.
-
Cause is actually the real data. It comes right from the Throwable object in Java. RootCause is actually created as the copy. Now while it may be that Cause is the real object and RootCause is the copy, I will say that since RootCause is documented, you should continue to use that.
Archived Comments
I noticed that the <cfdump> example you posted does not match the code above it, was this done purposely?
Yeah, sorry about that. The screen shot was sent to me by the guy who asked about the issue. It really isn't related.
'cause' was added to java.lang.Throwable in JDK1.4, which we started to use for build from CF8. But 'rootCause' were added in CF exceptions much earlier than that. We could not have removed 'rootCause' after ''cause" was introduced :-)
So 'RootCause' is the *real* data and in most of the cases 'cause' will be same as "RootCause". So as Ray said, one should continue using rootCause.