The World's Favorite Open Source GPL J2EE CFML Runtime Engine

BlueDragon Developer's Journal

Subscribe to BlueDragon Developer's Journal: eMailAlertsEmail Alerts newslettersWeekly Newsletters
Get BlueDragon Developer's Journal: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn

Open BlueDragon Authors: Reuven Cohen, Elizabeth White, Michael Sheehan, John Gauntt, Salvatore Genovese

Related Topics: Open BlueDragon Developer's Journal, ColdFusion on Ulitzer, Java EE Journal

BlueDragon: Article

Errors in Your Code

Handling, debugging, and testing for them

Debugging: Resolving Errors
When it comes to resolving errors, there are a variety of tags and techniques to assist you. Some are features to help you while running a request to provide additional information to track the program's state, while another is the ability to do interactive step debugging, and the last are related to getting system diagnostics. We don't have room to elaborate on these, but do be aware of them.

Additional Info To Track Program State
The first set of debugging tools, some of which are widely used while others are still a surprise to many, are the debugging info enabled in the Admin console, CFDUMP, CFLOG, CFTRACE, CFTIMER, and the cfstat command-line utility (BlueDragon doesn't currently support the last two). Even CFOUTPUT and CFABORT can be useful techniques when debugging. These topics have been covered in more depth in the following articles (and of course, the documentation):

There is also a new article this month related to the above: "Faster debugging with CFTIMER and CFTRACE", by Shlomy Gantz.

I'd also like to point out that BlueDragon offers a useful tag called CFDEBUGGER to supplement those above. It traces all the lines of CFML code executed in a given request, something that CF developers have never had. I wrote about it in a past CFDJ article: CFDEBUGGER (November 2003)

Interactive Step Debugging
Of course, when some think of debugging they immediately think of interactive "step" debugging, and those folks have long complained that CFML lacked such a capability (while some others don't miss it at all). As we went to press, the folks at (Intergral GMBC) released their FusionDebug tool, which is an Eclipse plug-in that finally provides step debugging for ColdFusion MX. Learn more at It's something I'm excited about. While many never knew it, we did indeed have debugging available in ColdFusion 5 and before by way of ColdFusion Studio (or today's HomeSite+). I've mentioned it in, "Browsing within CF Studio/HomeSite+" (August 2003) I even walked folks through using it in a 1999 presentation, available at One reason I never wrote about it here is that it didn't always work. Still, I'll point out that the official documentation, which many never knew existed, was in Chapter 9 of Using ColdFusion 5 Studio at It should be possible to get it working with CF Studio and/or HomeSite+ with ColdFusion 5, if you still have them both.

System Diagnostics
Of course, sometimes to understand error situations you need more information than just what's reflected in running the current page. There could be other activities or problems in the environment that are impacting your code. When it comes to gathering diagnostics to understand and resolve problems, you should consider taking advantage of the built-in logs, available in the aforementioned ColdFusion logs directory. There's also an interface to view them in the Admin console.

Beyond that, though, there's even more powerful analysis of what's going on in your environment available by way of two commercial (yet reasonably priced) tools that have come out in the past year or so: SeeFusion at and FusionReactor at Both are available on a free trial basis so check them out.

There may be problems that are outside of ColdFusion that are affecting you. Be sure to consider analyzing your Web server, database, network, and the operating environment of the machine running ColdFusion. There are logs and analysis tools for each that are beyond the scope of this article. Finally, another vital tool when solving problems in CFML is simply knowing what you should and shouldn't be doing in CFML. Don't forget that you have documentation available at (no, the domain name hasn't changed yet). And more than just the CFML reference, there's a 900+ page Developer Guide and more.

Testing: Preventing Errors in the First Place
While it's admirable to do a better job catching, handling, and debugging errors when they occur, shouldn't we try to prevent them in the first place? There are several ways you may be able to test your code to prevent errors occurring at all, as we will discuss, ranging from unit testing to syntax checking to validating your page input and output.

Unit Testing
To prevent bad code from getting into production many would recommend doing better unit testing, a subject within the broader topic of test-driven development. CFML offers various implementations of such unit-testing tools ranging from test harnesses to cfunit and cfcunit, as discussed in:

Note that cfunit used to be part of the Developer Resource Kit (DRK) but it's now available at the site above. There are still other forms of testing to keep in mind.

CFML Syntax Checking
Since CFML isn/t a compiled language, many errors slip by because we don't need to "run a compile step" before releasing our code into the wild. We may have syntax errors that would cause a page to fail as soon as it's run. How can we catch them without actually running every page? Again, good unit tests would help, but until you implement them, there's still another approach.

Did you know that there are various means to check your CFML code's syntax before releasing it? Since release 4, the Admin console has had a mechanism that lets you point to a directory of code. It will analyze your CFML and report if there are problems. While in CFMX it's formally called a Code Compatibility Analyzer, with a focus on checking code from previous releases, it also does CFML syntax checking (see the "Advanced Options"). There has also been one in CF 4 and 5. Note that you can point it at an entire directory (and optionally recurse into subdirectories), so it's definitely something to consider as a regular part of testing. See the online help in the Admin console for more information.

Perhaps you're perturbed that that tool is a Web interface requiring you to enter data in a form. You want a command-line tool. I'm not aware of a means to call that compatibility analyzer from the command line, but did you know that CFMX 6.1 added a command-line precompile tool? It's in the /bin directory as cfcompile.bat. While the primary purpose is performance improvement (saving the auto-compile that takes place on first load of the page into server memory), it will report if there are any errors during evaluation of the CFML, so it can act very much like the missing compilation step that other developers use to catch errors early. Again, it is a command-line tool, and it does by default compile all templates in a given directory.

See Chapter 5 of the CFMX 7 Administration manual (but not in the CFMX 6.1 manual) for more information. It's also discussed in the following article. Though the focus is on J2EE Web application deployment, the discussions of cfcompile are still broadly useful: "Deploying Applications with ColdFusion MX 7" (Dave Carabetta, March 2005)

I'd like to point out also that I had discussed the benefits of such a precompile tool in a two-part series. Though it was written before the tool was released officially in 6.1, some of the info may still benefit:

Input and Security Validation
Still another form of testing to consider before you turn your application out for production implementation is a range of tests that focus on ensuring that the application avoids errors by preventing inappropriate input or cross-site scripting as discussed in: Output Validation
Other forms of testing focus on the output of your pages such as validating your HTML code (accessibility checking, CSS validation, link checking, and spell checking) as well as regression, load, and concurrency testing. I covered all of these in "E-Testing: Debugging Your Projects" (October 2001)

Other Error-Related Topics
There are still other topics that are tangentially (or perhaps directly) related to error handling, including handling errors from CFMAIL, using the CFTHROW tag, doing site monitoring, load testing, and leveraging version control to manage your code better and recover from erroneous code releases. Again, there's no room to elaborate, but I'll point out one more article that covers a range of topics including error handling, testing, and source control: "7 Habits of Highly Effective ColdFusion Developers" (Robi Sen, February 2004)

And while I'm mentioning error-handling articles, some will get value out of a past article on handling errors in JavaScript: "Error Handling in JavaScript" (Steve Bryan, October 2002)

Finally, I'll also point out that in this month's issue there is an article from Joshua Curtiss on yet another error-handling concept, "Handling 404 Errors for a Migrated Blog".

I hope this trip through the archives of the CFDJ focusing on error handling, debugging, and testing will help improve the quality of your CFML development.

More Stories By Charlie Arehart

A veteran ColdFusion developer since 1997, Charlie Arehart is a long-time contributor to the community and a recognized Adobe Community Expert. He's a certified Advanced CF Developer and Instructor for CF 4/5/6/7 and served as tech editor of CFDJ until 2003. Now an independent contractor ( living in Alpharetta, GA, Charlie provides high-level troubleshooting/tuning assistance and training/mentoring for CF teams. He helps run the Online ColdFusion Meetup (, an online CF user group), is a contributor to the CF8 WACK books by Ben Forta, and is frequently invited to speak at developer conferences and user groups worldwide.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.