Ask a Jedi: What is Cause and RootCause in ColdFusion exceptions?

This post is more than 2 years old.

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:

<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>

&lt;cfreturn true&gt;


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:

  1. First, Cause is a copy of RootCause. You don't have to look at them both for information about the error.

  2. 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.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Scott Stroz posted on 1/20/2010 at 7:01 PM

I noticed that the <cfdump> example you posted does not match the code above it, was this done purposely?

Comment 2 by Raymond Camden posted on 1/20/2010 at 7:04 PM

Yeah, sorry about that. The screen shot was sent to me by the guy who asked about the issue. It really isn't related.

Comment 3 by Rupesh Kumar posted on 1/21/2010 at 4:09 PM

'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.