I have this on all my cf pages, and it works fine. Amend it to suit your own
requirements. There are a few APPLICATION variables that I set in the
Application.cfm file, so I can put this code in my standard template:
<!--- Open with a cftry for structured error handling --->
<cftry>
All your code goes here
<!--- Structured error handling --->
<cfcatch type="Database">
<!--- Database error -- inform user --->
<table align="center">
<tr>
<td height="50"> </td>
</tr>
<tr>
<td align="center"><font face="Arial,Helvetica,sans-serif"
color="#000033"><h2>DATABASE ERROR
<cfoutput>#CFCATCH.nativeerrorcode#</cfoutput></h2></font></td>
</tr>
<tr>
<td align="center"><font face="Arial,Helvetica,sans-serif"
color="#000033"><b>Sorry, we are experiencing database problems at this
time.<br> Please try again later. The site administrator has been informed
of the problem.</b><br>
You can e-mail the site administrator directly by clicking <a
href="mailto:<cfoutput>#APPLICATION.adminemail#</cfoutput>">here</a><br>
<!--- Leave this here for debugging......remove when site goes
live --->
<cfoutput>Message: #CFCATCH.message#
Error Code: #CFCATCH.nativeerrorcode#
SQL State: #CFCATCH.sqlstate#
Detail: #CFCATCH.detail#</cfoutput>
</font></td>
</tr>
</table>
<!--- Now email admin with details of error --->
<cfmail to="#APPLICATION.adminemail#" from="#APPLICATION.fromemail#"
subject="EXCEPTION: #CFcatch.type#">
Message: #CFCATCH.message#
Error Code: #CFCATCH.nativeerrorcode#
SQL State: #CFCATCH.sqlstate#
Detail: #CFCATCH.detail#
</cfmail>
</cfcatch>
<cfcatch type="Any">
<!--- General error -- inform user --->
<table align="center">
<tr>
<td height="50"> </td>
</tr>
<tr>
<td align="center"><font face="Arial,Helvetica,sans-serif"
color="#000033"><h2>PROCESSING ERROR</h2></font></td>
</tr>
<tr>
<td><font face="Arial,Helvetica,sans-serif"
color="#000033"><b>Apologies
but there has been an error in the processing of your request.<br> Please
try again. The site administrator has been informed of the problem</b><br>
You can e-mail the site administrator directly by clicking <a
href="mailto:<cfoutput>#APPLICATION.adminemail#</cfoutput>">here</a>
<br>
<!--- Leave this here for debugging......remove when site goes
live --->
<cfoutput>Message: #CFCATCH.message#
Detail: #CFCATCH.detail#</cfoutput></font></td>
</tr>
</table>
<!--- Now email admin with details of error --->
<cfmail to="#APPLICATION.adminemail#" from="#APPLICATION.fromemail#"
subject="EXCEPTION: #CFcatch.type#">
Message: #CFCATCH.message#
Detail: #CFCATCH.detail#
</cfmail>
</cfcatch>
</cftry>
-----Original Message-----
From: Bryan LaPlante [mailto:[EMAIL PROTECTED]]
Sent: 22 May 2001 09:44
To: CF-Talk
Subject: Re: cfcatch and email
Never tried to do that inside of a cfcatch block before but could you just
populate a variable with the email message and then outside the try block
check to see if the message is not empty and then send an email if so?
Bryan
----- Original Message -----
From: "sebastian palmigiani" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Monday, May 21, 2001 10:39 PM
Subject: cfcatch and email
>
> I want to send an email with database error info using cftry/cfcatch. But
it
> is not working. Am I trying to do something that can't be done within a
> cfcatch block?
>
> Sebastian
>
> -------------------------------
>
>
> <cftry>
>
> <cfquery name='foo' datasource='foo'>
>
> Select * from members
>
> </cfquery>
>
> <cfcatch type="database">
>
> <!--- EMail WebMaster --->
> <cfmail from="[EMAIL PROTECTED]"
> type="HTML"
> to="[EMAIL PROTECTED]"
> subject="Database Error">
>
> Date: #DateFormat(Now(), "MM D, YYY")# #TimeFormat(Now(), "h:mm tt")#<br>
> Error Type: #CFCATCH.Type#<br>
> Message: #CFCATCH.Message#<br>
> Template: #CGI.CF_Template_Path#<br>
> Referer: #CGI.HTTP_Referer#<br><br>
> Details:
> #CFCATCH.Detail#<br><br>
> </cfmail>
>
> <cflocation url="index.cfm?go=Error"> --->
>
> </cfcatch>
>
> </cftry>
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists