Abort is an Error

I've been trying to use application.cfc more in my work and I've found another little 'gotcha'. Lets walk through this one step by step. A LOT of people use a CFABORT in their code to control the flow of their page. The logical assumption is that when the CFABORT is called, the page stops dead in its tracks. If the showerror attribute is set inside the CFABORT then an exception error is thrown. This acts like a slightly cut down version of the CFTHROW tag. But when you have not set the showerror attribute, you don't expect an error, right?

Guess what. There is a specific situation where the use of a simple CFABORT will be considered an error and this is (or should be) a common situation. When you have an application.cfc with an onRequest() and an onError() method and the template being called by the onRequest() has a CFABORT in it, the onError will detect that usage of the CFABORT as an error.

The error message will be supremely unhelpful as it simply says that there's an error in the onRequest method of the application.cfc. You have to look through the stack trace and tag context to see that the error was on a specific line and the last tag to fire was a CFABORT. But even then, you would not think this was the problem as there is no logical reason for it to be the problem.

The solution is to either not use CFABORT for page control when using these two methods or to remove one of those methods from your application.cfc. Either one can be removed and the error is gone.

So what has this taught me? Not that there is a strange combination of code in ColdFusion. Not that there is a potential bug in how onError handles error events. This has taught me that there are just not a lot of people using the application.cfc template. If there were, this problem would have appeared much earlier. Maybe it has and I missed it, but somehow I doubt that.

Comments
Chris Rockett's Gravatar Could also mean that not that many people are using cfabort for page flow anymore. Since I've been using fusebox, I almost never use cfabort because it breaks the fusebox so that content variables won't show the page content at the end of the request. Instead I use cfexit or cfthrow. Also in the context of cfcs, I never use cfabort as the behavior is not often what I might expect.
# Posted By Chris Rockett | 5/12/06 8:56 PM
Tim's Gravatar Not sure about your situation but this has "fixed" cfabort for me. Add this to your onerror method in application.cfc

<cfif arguments.exception.rootCause eq "coldfusion.runtime.AbortException">
   <cfreturn/>
</cfif>
# Posted By Tim | 5/22/06 4:23 PM
Tim's Gravatar Not sure about your situation but this has "fixed" cfabort for me. Add this to your onerror method in application.cfc

<cfif arguments.exception.rootCause eq "coldfusion.runtime.AbortException">
   <cfreturn/>
</cfif>
# Posted By Tim | 5/22/06 4:24 PM
Michael Dinowitz's Gravatar This very blog is using cfabort for flow control and does not have an application.cfc. When Raymond upgrades it to application.cfc this will have to be altered or one of the offending methods will have to be skipped (probably the onRequest).
# Posted By Michael Dinowitz | 5/28/06 11:48 AM
north face jackets on sale's Gravatar Aw, it was a top quality content. Actually I would like to write like this as well - taking time and real energy to bring about an excellent post... however what can I say... I procrastinate an awful lot and by no means appear to get things completed...
# Posted By north face jackets on sale | 10/6/11 8:47 PM
Microsoft Office's Gravatar in different folders for easy accessibility.
# Posted By Microsoft Office | 12/13/11 3:42 AM
cheap watches's Gravatar As consumers buy in bulk NET and Web browser to enjoy their homes, online traders and wholesalers of what makes a comfortable shopping online business of their host.
# Posted By cheap watches | 1/14/12 10:28 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9. Contact Blog Owner
House of Fusion | ColdFusion Jobs @ House of Fusion | Fusion Authority