May 30, 2006
Several people have noticed that if you are using
Application.cfc and have an
onError() method in it, when you use
cfabort to end a request, it will trigger the
onError() method. This seems pretty counter-intuitive to a lot of people so I figured I'd post some clarifications.
First, you only get the error if you also have an onRequest() method in Application.cfc. If you have no onRequest() method and you use cfabort, then onError() will not be called.
Second, if you read the docs for cfabort it should be clear that, in general, cfabort is considered to be an error condition. The docs are very explicit about the interaction between cfabort, cferror and the presence or absence of the showError= attribute on cfabort.
If you don't have onError() and you use the showError= attribute, then cfabort will terminate execution of the request and display the error to the user (as expected).
If you do have onError() and you use the showError= attribute, then cfabort will terminate execution of the request and onError() will be invoked (as expected).
So the edge case to watch for is where you have both onRequest() and onError() and you do not have showError=. Caveat programmer.
Comments
It might be worth nothing that cflocation will call the OnError event also. In my experience, this only happens if the cflocation is in the Application.cfc.
I read about this in Blogs before, so believe this is a known bug.
Posted By Jeff Houser / Posted At
5/30/06 10:52 PM
I use this code as a workaround in the onError function in my application.cfc
<cfif arguments.Exception.Type eq "coldfusion.runtime.AbortException"> <cfreturn> </cfif>
Posted By Jos / Posted At
5/31/06 3:05 AM
I had been hit by this same issue for several weeks and finally got around to fixing it just last Thursday. I found 2 excellent blog entries that provide great solutions for the fix. 1. Steve Bryant's blog (steve.coldfusionjournal.com) entry on 3/22/2005 titled 'Hide Your Errors (Application Events: onError)' 2. Ray Camden's blog (ray.camdenfamily.com) entry on 2/7/2005 titled 'Warning About Application Events'
Now just to find a solution for the onSessionEnd and onApplicationEnd errors that are getting thrown. Any ideas?
Posted By Jason Daiger / Posted At
6/1/06 9:26 PM
This happens to me and I DON'T have the onRequest() method as stated above in Sean's post. I used a solution similar to Jos' idea (thanks for the input). My code looks like this: <cfif arguments.Exception.RootCause.Type is "coldfusion.runtime.AbortException"> <cfreturn true> </cfif> Remember your returntype="void" in your onError() method, so don't return "true".
Posted By Glenda Vigoreaux / Posted At
8/1/06 8:07 PM
I had this problem too! in application.cfc with an onRequestStart function and using cfabort if session did not exist the onError function was being called by cfabort..... I modified Jos's example and it worked great:
<cfif arguments.Exception.RootCause.Type eq "coldfusion.runtime.AbortException"> <cfreturn> </cfif>
Posted By Andrew Grosset / Posted At
12/12/07 10:21 AM
Post Your Comments
Hosting provided by