OnError Function Problem?

Posted on 2011-10-22
Last Modified: 2012-05-12
I have very recently been getting and error in my application.cfc OnError function.  Please see the attached code for my CFC section and the error I am getting on my screen instead of the program that never get's control.  I have a test program that just has :

<cfset a = 5/0>

I am getting :
The error occurred in C:\ColdFusion8\wwwroot\mysite\Application.cfc: line 24
22 :    
23 :       <cflog file="SMMCerrorlog"  type="error" text="#arguments.exception.message#">
24 :     <cflog file="SMMCerrorlog"  type="error" text="Root Cause Message: #arguments.exception.rootcause.message#">
25 :
26 :       

<cffunction name="onError" returnType="void" output="true">
	<cfargument name="exception" required="true">
	<cfargument name="eventname" type="string" required="true">
    <cfset var errortext = "">
	<cflog file="SMMCerrorlog"  type="error" text="#arguments.exception.message#">
    <cflog file="SMMCerrorlog"  type="error" text="Root Cause Message: #arguments.exception.rootcause.message#">

	<cfsavecontent variable="errortext">
	An error occurred: http://#cgi.server_name##cgi.script_name#?#cgi.query_string#<br />
	Date/Time: #dateFormat(now(), "mm/dd/yyyy")# #timeFormat(now(), "long")#<br />
	<cfdump var="#arguments.exception#" label="Error">
	<cfdump var="#form#"    label="Form">
	<cfdump var="#url#"     label="URL">
    <cfdump var="#session#" label="SESSION">
    <cfdump var="#cgi#"     label="CGI">
    <cfdump var="#cookie#"  label="COOKIE">
      subject="Error: #arguments.exception.message#"
      username="" spoolenable="no" 
	<cflocation url="/error.cfm">

Open in new window

Error message I get:
Question by:hefterr
    LVL 51

    Accepted Solution

        > #arguments.exception.rootcause.message#

    I don't know why they put that in the examples ... because not every exception has a root cause! Afaik, t's created when one type of error bubbles up and triggers another.  For example, run a query with a bad datasource name.  The "root cause" exception will be:

         java.sql.SQLException: Datasource notfound could not be found.

    But it bubbles up and is finally transformed into a different error. CF captures all of them but adds a key called "rootcause" so you know what the original error was.  

        coldfusion.tagext.sql.QueryTag$DataSourceException: Datasource "xxxx" could not be found.

    With divide by zero error's there's only a single exception. So there's no "root cause".  You'll have to run a check to verify that key exists first.

    <cfif structKeyExists(arguments.exception, "rootcause")>
                use the root cause message
                use arguments.message instead
    LVL 1

    Author Comment

    Hi _agx_,
    Not sure I quite understand.  This is what I have now.

    <cflog file="SMMCerrorlog"  type="error" text="#arguments.exception.message#">
    <cflog file="SMMCerrorlog"  type="error" text="Root Cause Message: #arguments.exception.rootcause.message#">

    Can I always just use arguments.exception.message?  Is there other information (sometimes) in arguments.exception.rootcause.message?

    Is it an either or situation?

    Thanks again,

    LVL 51

    Expert Comment

    Sorry, I didn't notice the first log call using #arguments.exception.message#.  The 1st log call is fine because exception.message should always exist.  But exception.rootcause won't. So any time you use it, you have to verify it exists 1st:

    <cfif structKeyExists(arguments.exception, "rootcause")>
        <cflog file="SMMCerrorlog"  type="error" text="Root Cause Message: #arguments.exception.rootcause.message#">

    LVL 1

    Author Closing Comment

    Thanks again for you expertise!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
    Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now