Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

exception handling, kindly help.

Status
Not open for further replies.

cfdeveloper

Programmer
Nov 20, 2003
144
GB
Hello everybody,
I'm hoping someone can help me. I am working on this exception handling code. I have written a custom error handler that displays a custom error message when a coldfusion error occurs and sends an email to the administrator. I want to append the complete error
block to the email body. i.e essentially the raw error message you would see if you didn't have the cftry and cfcatch.

ex:

Error Occurred While Processing Request Variable NAME is undefined.

The error occurred in c:\inetpub\ line 494
Called from c:\inetpub\ line 457
Called from c:\inetpub\ line 226
Called from c:\inetpub\ line 1

492 : </cfif>
493 : , '#LSDateFormat(Now(),'yyyy/mm/dd')# #LSTimeFormat(Now(),'HH:mm:ss')#',
494 : '#Name#'
495 : )
496 : </cfquery

Here is my code:

<cftry>

<cfcatch type="any">
<cf_caughtIt catchMessage="#cfcatch.message#">
</cfcatch>

</cftry>

caughtIt.cfm

<cfparam name="attributes.catchMessage" default="">

<CFMAIL
type="HTML"
FROM="#cgi.server_name#@domain"
TO="#administrator#"
SERVER="someserver"
PORT="25"
SUBJECT="#cgi.SCRIPT_NAME#">

<h2>Details</h2>
<cfif attributes.catchMessage neq "">
<cfdump var="#attributes.catchMessage#">
</cfif>

<h2>Form Info</h2>
<cfdump var="#form#">

<h2>URL Details</h2>
<cfdump var="#url#">

</CFMAIL>

I would appreciate your help
Regards,
cfcoder
 
Your method is inefficient... But its either not working because
1.) Name is not being set and/or
2.) Custom tags call variables that are local to the calling page in the caller. scope.. IE, your page would call #name# but CaughtIt.cfm would call #caller.name#
3.) It always seemed to me that name is a bad name for variables.

Read up on CFERROR

It will allow you do to everything you want without invoking a custom tag or a clumsy substitution.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
I do something similar to this, here's the error values I pass in my emails.
Code:
<strong>Date/Time:</strong> #DateFormat ('#error.DateTime#', 'mm/dd/yy')#, #TimeFormat ('#error.DateTime#', 'hh:mm tt')#<BR><BR>
<strong>Browser</strong> #error.Browser#<BR><BR>
<strong>Diagnostics:</strong> #error.Diagnostics#<BR><BR>
<strong>Template:</strong> #error.Template#<BR><BR>
<strong>HTTP Referer:</strong> #error.HTTPReferer#<BR><BR>
<strong>Query String:</strong> #error.QueryString#<BR><BR>
<strong>RootCause:</strong> #error.RootCause#<BR><BR>
It may not look like you want it, but most of the information is there.



Hope This Helps!

Ecobb
Beer Consumption Analyst

"My work is a game, a very serious game." - M.C. Escher
 
Thank you guys for replying to my thread. Ecobb I tried your code, but still don't get back a empty "error" structure

<cftry>

<cfcatch type="any">
<cfdump var="#error#"> <!--- I want to see what is returned in this structure --->
<cfabort>
<cf_caughtIt catchMessage="#cfcatch.message#">
</cfcatch>

</cftry>

Any thoughts?
 
I'm sorry I made a typo mistake in my last post. What I meant was that the "error" structure is empty when I try to dump it
 
Seriously, consider an error template, but that's up to you..

Try calling an error variable directly... get anything?

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Hi there, sorry for not getting back sooner. I've been banging my head trying to find a solution ALL day. I would really appreciate your help. I am already using a error template, its a custom tag that's wrapped around the cfcatch tags.

<cfcatch type="any">
<cf_caughtIt catchMessage="#cfcatch.message#">
</cfcatch>

I modified caughtIT.cfm a bit. It now contains the custom error message. What I also want to do in the background now is send the email to the administrator with the complete error information.

Here is the code:

<cfparam name="attributes.catchMessage" default="application error">

<table>
<tr>
<td>
Oops! an error has occurred
</td
</tr>
</table>

I hope I'm making sense? I want to now add the cfmail tag either on this page or in another custom tag just below the code above that has the detailed error info in the email body. Can you please please show me how to do this man! I would be so thankful to anybody who does.


I was reading somewhere that the error scope only exists in an error template, not in a try/catch block. There is a cfcatch scope for try/catch (but I think you can't dump it anymore with the latest CFMX updater)

CatchIT.cfm is a error template. I beleive I should be using the cferror tag, I don't know how to use this.#

This is what I want to output in the email

<CFMAIL
type="HTML"
FROM="#cgi.server_name#@domain"
TO="#administrator#"
SERVER="someserver"
PORT="25"
SUBJECT="#cgi.SCRIPT_NAME#">

<h2>Error</h2>
<cfif isdefined("Error")>
<cfdump var="#error#">
<cfelse>
No Error info defined
</cfif>

<h2>Details</h2>
<cfif attributes.catchMessage neq "">
<cfdump var="#attributes.catchMessage#">
</cfif>

<h2>Form Info</h2>
<cfdump var="#form#">

<h2>URL Details</h2>
<cfdump var="#url#">

</CFMAIL>

I would really apprecaite your help
Regards
cfcoder
 
CatchIt.cfm could be an error template but its not... not by CFERROR (which is the standard for sitewide processing... CFCATCH action is great for one error or for filter for an error from one page.. but CFERROR is what you use when you're monitoring many pages.)

Here is the code for a file called error.cfm... This is a slightly modified version of what I use... I invoke some processes that I can't share here.

Code:
<CFMAIL
  from="EMAIL_ADDRESS_HERE"
  to="Error Reporter <EMAIL_ADDRESS_HERE>"
  subject="Site Error!" type="html">
<html>
<head>
  <title>Error Reporter</title>
</head>
<body>
  <cfoutput>File: #Error.Template#<br>
  #expandpath(error.template)#<br><br>
  Time: #Error.DateTime#<br><br>
  Query String: #Error.QueryString#<br><br>
  Error Diagnostic:<br>
  #Error.Diagnostics#</cfoutput>

  <!--- I dump form and session so I can see what the user
        submitted and who the user was.. It tells me a lot
        about what they were trying to do. --->
  <cfdump var="#form#">
  <cfdump var="#session#">
</body>
</html>
</cfmail>

<cftry>
  An error has occurred, We've been informed of the diagnostics.. If you know what specific actions you took  to cause the error, please email EMAIL_ADDRESS_HERE.
<!--- It might seem silly for simple text to be wrapped in cftry/cfcatch but in my error file, I have some actions here that db info about the error and I can't afford for the db actions to throw the error template so I wrap this in a cftry. I know it looks odd, but I'm leaving as much as I can in as much of a form as I can. --->
  <cfcatch>An error has occurred, We've been informed of the diagnostics.. If you know what specific actions you took to cause the error, please email EMAIL_ADDRESS_HERE.
  </cfcatch>
</cftry>

Error.cfm should be placed in the same page as application.cfm and then invoked with:

Code:
<cferror 
  template="error.cfm"
  mailto="EMAIL_ADDRESS_HERE"
  type="exception"
  Exception="ANY">

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Hi and thanks for posting the code. I'm afraid I can't implement your logic because my application uses a lot of iframes and the custom error message can have a green background or a orange background depending on the page the error occurred and to be able to do that I use the custom tag inside the cfcatch block and "color" is the one of the attributes of this tag.

<cfcatch type="any">
<cf_caughtIt catchMessage="#cfcatch.message#" color="red">
</cfcatch>

I still don't know how to call the cferror tag. To give you a better idea, here is what I'm trying to do

Step 1: Exception occurred. error code wrapped around cftry and cfcatch blocks
Step 2: custom tag "caughtIt" called inside the cfcatch tag, see above.
Step 3: caughtIt.cfm displays the custom error message and emails the error details to the administrator i.e form, session, url info. I'm trying to get detailed error info (ie line error occurred, root cause, diagnostics etc. This info is contained in the "error" structure that is returned by the cferror tag.

Now then, if I can somehow call the cferror tag inside application.cfm (as you suggested) or some other way I can get something out. The problem is (don't know how serious this is), but my application uses iframes. If the error occured in a inner iframe, how do I get to display the error message in that iframe and not on the top-level iframe? You see what I'm saying. I hope I'm making sense guys. I'll appreciate your help

Regards
cfcoder
 
can somebody plesae help me? I don't know what I'm supposed to do
 
If an error occurs in a frame, that's where the error stays... Same with IFRAMES.

Maybe step back on the colored customization... or find another way to go about it.. cferror is the standard here.

You could anayze the diagnostics of the error scope and color based on that...

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top