• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 477
  • Last Modified:

OnError Function Problem?

Hi,
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 :
Element EXCEPTION.ROOTCAUSE.MESSAGE is undefined in ARGUMENTS.
 
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 :       

Code:
<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">
	<cfoutput>
	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">
	
	</cfoutput>
	</cfsavecontent>
	
	<cfmail
      subject="Error: #arguments.exception.message#"
      from="support@mydomain.com"
      to="support@mydomain.com"
      server="mail.mydomain.com"
      password="mypassword"
      username="support@mydomain.com" spoolenable="no" 
      type="html">
		#errortext#
	</cfmail>
	
	<cflocation url="/error.cfm">
	
</cffunction>

Open in new window



Error message I get:
test-abend.doc
0
hefterr
Asked:
hefterr
  • 2
  • 2
1 Solution
 
_agx_Commented:
    > #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
<cfelse>
            use arguments.message instead
</cfif>
0
 
hefterrAuthor Commented:
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,
hefterr

0
 
_agx_Commented:
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:

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


0
 
hefterrAuthor Commented:
Thanks again for you expertise!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now