Skip to main content
August 31, 2009
Question

onError in Application.cfc

  • August 31, 2009
  • 3 replies
  • 1017 views

My old method was using the <cferror template="error.cfm" type="exception"> in  application.cfm  and on the error.cfm page I would loop through the "error" collection and place the different error information in a table in the db. I am trying to accomplish this with Application.cfc without any luck. I see the standard method is to call the Exception argument but that collection does not contain all the information I need like the IP, browser or reffering page. Any ideas? I simply want the error collection so I can loop through it and insert into the db.

Thanks

    This topic has been closed for replies.

    3 replies

    September 1, 2009

    OK here was the workaround. Problem 1) was the exception collection changes based on the error type (expression, database etc).

    So below is the way I grabbed the various elements I needed to insert intot he db.

    <!-- this function sits in my application.cfc - --->

    <cffunction name="onError" returnType="void" output="true">

      <cfargument name="Exception" required="true">

      <cfargument name="EventName" required="true">

    <!--- grab the nested aray in the structure (all I need is the first element of the array) --->

      <cfset mystruc = exception.tagcontext[1]>

    <!---- lets put the error data in the DB using my old cfc --->

    <cfinvoke component="cfc.public" method="AddError" returnvariable="NoSHow">

      <cfinvokeargument name="cf_diagnostics" value="#exception.cause.detail#. #exception.cause.message# on line #mystruc["LINE"]#">

      <cfinvokeargument name="Browser" value="#cgi.HTTP_USER_AGENT#">

      <cfinvokeargument name="RemoteAddress" value="#cgi.REMOTE_ADDR#">

      <cfinvokeargument name="HTTPReferer" value="#cgi.HTTP_REFERER#">

      <cfinvokeargument name="Template" value="#mystruc["TEMPLATE"]#">

      <cfinvokeargument name="cf_Message" value="#exception.cause.message#">

      <cfinvokeargument name="errortype" value="#exception.type#">

    <!--- because this only shows when it;s a database error we see if it's defined --->

      <cfif isdefined('exception.cause.sql')>

      <cfinvokeargument name="sqlsyn" value="#ltrim(rtrim(exception.cause.sql))#">

      </cfif>

    <!--- this is a session varibale that may or may not exists depending if they are logged in or not --->

      <cfif isdefined('session.id')>

      <cfinvokeargument name="SessionID" value="#Session.ID#">

      </cfif>

      <cfinvokeargument name="dtEntered" value="#now()#">

    </cfinvoke>

    <!--- here I include an oops page --->

    <cfinclude template="error.cfm">

    </cffunction>

    September 1, 2009

    Yes, I have grabbed those variables with the CGI scope (it occured to me shortly after the post)  but I still cant get the raw_trace element that givees the line number of the error. Pretty important info when you are trying to troubleshoot. The  element is in a structure, within an array, within a structure, within a structure. The error collection was much easier to work with and contained everything needed to trouble shoot. I am working on a loop to get all the data I need from the exception collection. I will post it when I am done in the event anyone else has this problem.

    Inspiring
    September 1, 2009

    Aren't those additional things you need just duplicated from the CGI scope anyhow?

    --

    Adam