Entries for month: April 2007

In Honor of the Victims at Virginia Tech

One Day Blog Silence

No Comments

Error when cflocation is ran within onRequestStart

There is some code in one of the projects I am working on that checks if a user is logged in within the onRequestStart application function. If the user is not logged in, the code redirects them to the login page using a cflocation. Although there is no visual error, i kept getting error emails thru my onError function stating there was a coldfusion.runtime.AbortException error happening:

An exception occurred when invoking a event handler method from Application.cfc The method name is: onRequestStart.

Reading various posts on this error on the web, I found that the this problem is well known and found some work-arounds. Here is one of them...

Within your onError function you can filter out the AbortException errors by doing this:

<cffunction name="onError" returntype="void">
   <cfargument name="exception" required="true">
   <cfargument name="eventname" type="string" required="true">

   <cfswitch expression="#arguments.exception.rootcause.type#">
      <cfcase value="coldfusion.runtime.AbortException">
         <!--- do nothing --->
         <cfreturn />
      </cfcase>
      <cfdefaultcase>
         <!--- error handling code here --->
         <cfdump var="#exception#" label="Exception">
      </cfdefaultcase>
   </cfswitch>
   
</cffunction>

That did the trick!

No Comments