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

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> <cfreturn true> </cffunction>

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 developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA https://www.raymondcamden.com

Comments